<?php
namespace Home\Controller;

use Think\Controller;
use Think\Log;//日志

class SettingController extends Controller {
	
	public function home(){
		$house=M('house');
		$houselist=$house->select();
		$this->assign('houselist',$houselist);
        $this->display('Setting:home');
	}
	
	public function loadDevice(){
		$houseid = I("rid");
		$nm3000=M('nm3000');
		$bw800=M('bw800');
		$nm820=M('nm820');
		$nm410=M('nm410');
		
		$vnm3000status=M('vnm3000status');
		$vbw800status=M('vbw800status');
		$vnm820status=M('vnm820status');
		$vnm410status=M('vnm410status');
		
		
		
		$list=array();
		if(empty($houseid)){
			$nm3000list=$nm3000->select();
			$bw800list=$bw800->select();
			$nm820list=$nm820->select();
			$nm410list=$nm410->select();
		}else{
			$nm3000list=$nm3000->where("houseid=".$houseid)->select();
			$bw800list=$bw800->where("houseid=".$houseid)->select();
			$nm820list=$nm820->where("houseid=".$houseid)->select();
			$nm410list=$nm410->where("houseid=".$houseid)->select();
		}
		
		foreach($nm3000list as $model){
			$p['type']='nm3000';
			$p['houseid']=$model['houseid'];
			$house=M('house');
			$houseModel=$house->where("rid=".$p['houseid'])->find();
			$p['housename']=$houseModel['housename'];
			$p['rid']=$model['rid'];
			$p['code']=$model['lxcode'];
			$p['name']=$model['lxname'];
			$vnm3000statusModel=$vnm3000status->where(" rid=".$p['rid'])->find();
			if(is_null($vnm3000statusModel['slrun'])){
				$p['online']=0;
			}else{
				$p['online']=1;
			}
			array_push($list,$p);
		}
		foreach($bw800list as $model){
			$p['type']='bw800';
			$p['houseid']=$model['houseid'];
			$houseModel=$house->where("rid=".$p['houseid'])->find();
			$p['housename']=$houseModel['housename'];
			$p['rid']=$model['rid'];
			$p['code']=$model['lxcode'];
			$p['name']=$model['lxname'];
			$vbw800statusModel=$vbw800status->where(" rid=".$p['rid'])->find();
			if(is_null($vbw800statusModel['day'])){
				$p['online']=0;
			}else{
				$p['online']=1;
			}
			array_push($list,$p);
		}
		//dump($nm820list);
		foreach($nm820list as $model){
			$p['type']='nm820';
			$p['houseid']=$model['houseid'];
			$houseModel=$house->where("rid=".$p['houseid'])->find();
			$p['housename']=$houseModel['housename'];
			$p['rid']=$model['rid'];
			$p['code']=$model['code'];
			$p['name']=$model['name'];
			$vnm820statusModel=$vnm820status->where(" rid=".$p['rid'])->find();
			if(is_null($vnm820statusModel['day'])){
				$p['online']=0;
			}else{
				$p['online']=1;
			}
			array_push($list,$p);
		}
		
		foreach($nm410list as $model){
			$p['type']='nm410';
			$p['houseid']=$model['houseid'];
			$houseModel=$house->where("rid=".$p['houseid'])->find();
			$p['housename']=$houseModel['housename'];
			$p['rid']=$model['rid'];
			$p['code']=$model['code'];
			$p['name']=$model['name'];
			$vnm410statusModel=$vnm410status->where(" rid=".$p['rid'])->find();
			if(is_null($vnm410statusModel['day'])){
				$p['online']=0;
			}else{
				$p['online']=1;
			}
			array_push($list,$p);
		}
		
		echo json_encode($list);
	}
	
	public function saveDevice(){
		$houseid=I('house');
		$rid=I('rid');
		$type=I('type');
		$code=I('code');
		$name=I('name');
		if(empty($code)||empty($name)){
			echo -1;
		}else{
			//type 分类
			if($type==0){
				//环控
				$nm820=M('nm820');
				//如果存在则更新
				if(empty($rid)){
					$rid=0;
				}
				$m=$nm820->where("rid=".$rid)->find();
				if(is_null($m)){
					$nm820Model['houseid']=$houseid;
					$nm820Model['name']=$name;
					$nm820Model['code']=$code;
					$nm820Model['sys_Alarm_TempSF']='0,0,0,0,0,0,0,0';
					$nm820Model['sys_Alarm_HumiSF']='0,0';
					
					$nm820Model['sensor_Wind']='0,0,0,0,0,0,0,0';
					$nm820Model['sensor_Channel']='0,0,0,0,0,0,0,0';
					$nm820Model['sensor_Cool']='0,0,0,0,0,0,0,0';
					$nm820Model['sensor_Spray']='0,0,0,0,0,0,0,0';
					$nm820Model['sensor_Heat']='0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0';
					$nm820Model['sensor_EX']='0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0';
					$nm820Model['sys_Relay']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
					$res=$nm820->add($nm820Model);
					
					if($res>0){
						$nm820table=M('nm820table');
						$nm820tableModel['code']=$code;
						$nm820tableModel['tempFig_Day']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['tempFig_Target']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_Day']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_STime']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_ETime']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_STemp']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_EHumi']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_On']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['cool_Off']='0,0,0,0,0,0,0,0,0,0,0';
						
						$nm820tableModel['spray_Day']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['spray_STime']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['spray_ETime']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['spray_STemp']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['spray_EHumi']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['spray_On']='0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['spray_Off']='0,0,0,0,0,0,0,0,0,0,0';
						
						$nm820tableModel['heat_STime']='0,0,0,0,0,0';
						$nm820tableModel['heat_ETime']='0,0,0,0,0,0';
						$nm820tableModel['heat_STemp']='0,0,0,0,0,0';
						$nm820tableModel['heat_ETemp']='0,0,0,0,0,0';
						$nm820tableModel['heat_On']='0,0,0,0,0,0';
						$nm820tableModel['heat_Off']='0,0,0,0,0,0';
						
						$nm820tableModel['light_STime']='0,0,0,0,0';
						$nm820tableModel['light_ETime']='0,0,0,0,0';
						$nm820tableModel['light_Level']='0,0,0,0,0';
						$nm820tableModel['light_STime1']='0,0,0,0,0';
						$nm820tableModel['light_STime2']='0,0,0,0,0';
						$nm820tableModel['light_ETime1']='0,0,0,0,0';
						$nm820tableModel['light_ETime2']='0,0,0,0,0';
						
						$nm820tableModel['wind_On']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_Off']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_dTemp']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_Side']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_Roller']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_VSFan']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_Top']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_Slide']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm820tableModel['wind_Fan']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						
						$res=$nm820table->add($nm820tableModel);
					}
				
				}else{
					$m['name']=$name;
					$m['code']=$code;
					$nm820->save($m);
				}
				echo $res;
			}
			else if($type==1){
				//环控
				$nm410=M('nm410');
				$nm410Model['houseid']=$houseid;
				$nm410Model['name']=$name;
				$nm410Model['code']=$code;
				if(empty($rid)){
					$rid=0;
				}
				$m=$nm410->where("rid=".$rid)->find();
				if(is_null($m)){
					$nm410Model['sys_Alarm_TempSF']='0,0,0,0,0,0,0,0';
					$nm410Model['sys_Alarm_HumiSF']='0';
					
					$nm410Model['sensor_Wind']='0,0,0,0,0,0,0,0';
					$nm410Model['sensor_Channel']='0,0,0,0,0,0,0,0';
					$nm410Model['sensor_Cool']='0,0,0,0,0,0,0,0';
					$nm410Model['sensor_Heat']='0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0';
					$nm410Model['sys_Relay']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
					$res=$nm410->add($nm410Model);
					//dump($res);
					if($res>0){
						$nm410table=M('nm410table');
						$nm410tableModel['code']=$code;
						$nm410tableModel['tempFig_Day']='0,0,0,0,0,0,0,0';
						$nm410tableModel['tempFig_Target']='0,0,0,0,0,0,0,0';

						$nm410tableModel['cool_Day']='0,0,0,0,0,0,0,0';
						$nm410tableModel['cool_STime']='0,0,0,0,0,0,0,0';
						$nm410tableModel['cool_ETime']='0,0,0,0,0,0,0,0';
						$nm410tableModel['cool_STemp']='0,0,0,0,0,0,0,0';
						$nm410tableModel['cool_EHumi']='0,0,0,0,0,0,0,0';
						$nm410tableModel['cool_On']='0,0,0,0,0,0,0,0';
						$nm410tableModel['cool_Off']='0,0,0,0,0,0,0,0';
						
						$nm410tableModel['heat_STime']='0,0,0';
						$nm410tableModel['heat_ETime']='0,0,0';
						$nm410tableModel['heat_STemp']='0,0,0';
						$nm410tableModel['heat_ETemp']='0,0,0';
						$nm410tableModel['heat_On']='0,0,0';
						$nm410tableModel['heat_Off']='0,0,0';
						
						$nm410tableModel['light_STime']='0,0,0,0,0';
						$nm410tableModel['light_ETime']='0,0,0,0,0';
						$nm410tableModel['light_Level']='0,0,0,0,0';
						$nm410tableModel['light_STime1']='0,0,0,0,0';
						$nm410tableModel['light_ETime1']='0,0,0,0,0';
						
						$nm410tableModel['wind_On']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_Off']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_dTemp']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_Side']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_Roller']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_VSFan']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_Top']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_Slide']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						$nm410tableModel['wind_Fan']='0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
						
						$res=$nm410table->add($nm410tableModel);
					}
				}else{
					$m['name']=$name;
					$m['code']=$code;
					$nm410->save($m);
				}
				
				
				
				echo $res;
			}
			else if($type==2){
				//料线
				$nm3000=M('nm3000');
				$nm3000Model['houseid']=$houseid;
				$nm3000Model['lxname']=$name;
				$nm3000Model['lxcode']=$code;
				if(empty($rid)){
					$rid=0;
				}
				$m=$nm3000->where("rid=".$rid)->find();
				if(is_null($m)){
					$res=$nm3000->add($nm3000Model);
				
					if($res>0){
						$nm3000sltime=M('nm3000sltime');
						$nm3000sltimeModel['lxcode']=$code;
						//$nm3000sltimeModel['slmodel']=0;
						//$nm3000sltimeModel['xlmodel']=0;
						for($i=1;$i<=20;$i++){
							$nm3000sltimeModel['sltime'.$i]='00:00';
						}
						$res= $nm3000sltime->add($nm3000sltimeModel);
						
						if($res>0){
							$nm3000xltime=M('nm3000xltime');
							$nm3000xltimeModel['lxcode']=$code;
							for($i=1;$i<=20;$i++){
								$nm3000xltimeModel['xltime'.$i]='00:00';
							}
							$res=$nm3000xltime->add($nm3000xltimeModel);
						}
					}
				}else{
					$m['lxname']=$name;
					$m['lxcode']=$code;
					$nm3000->save($m);
				}
				
				
				
				
				echo $res;
			}
			else if($type==3){
				//饲喂
				$bw800=M('bw800');
				$bw800Model['houseid']=$houseid;
				$bw800Model['lxname']=$name;
				$bw800Model['lxcode']=$code;
				if(empty($rid)){
					$rid=0;
				}
				$m=$bw800->where("rid=".$rid)->find();
				if(is_null($m)){
					if($res>0){
						$bw800caltable=M('bw800caltable');
						$bw800caltableModel['lxcode']=$code;
						for($i=1;$i<=10;$i++){
							$bw800caltableModel['index']=$i;
							$bw800caltableModel['weight']=0;
							$res= $bw800caltable->add($bw800caltableModel);
							if($res<0){
								break;//错误结束
							}
						}
						
						
						if($res>0){
							$bw800timetable=M('bw800timetable');
							$bw800timetableModel['lxcode']=$code;
							for($i=1;$i<=10;$i++){
								$bw800timetableModel['index']=$i;
								$bw800timetableModel['timestart']='00:00';
								$bw800timetableModel['timeend']='00:00';
								$bw800timetableModel['percent']=0;
								$res=$bw800timetable->add($bw800timetableModel);
								if($res<0){
									break;//错误结束
								}
							}
							
							if($res>0){
								$bw800cctable=M('bw800cctable');
								$bw800cctableModel['lxcode']=$code;
								for($i=-8;$i<=18;$i++){
									$bw800cctableModel['day']=$i;
									$bw800cctableModel['weight']=0;
									$res=$bw800cctable->add($bw800cctableModel);
									if($res<0){
										break;//错误结束
									}
								}
								
								if($res>0){
									$bw800jctable=M('bw800jctable');
									$bw800jctableModel['lxcode']=$code;
									for($i=-8;$i<=18;$i++){
										$bw800jctableModel['day']=$i;
										$bw800jctableModel['weight']=0;
										$res=$bw800jctable->add($bw800jctableModel);
										if($res<0){
											break;//错误结束
										}
									}
								}
								
							}
							
						}
					}
				}else{
					$m['lxname']=$name;
					$m['lxcode']=$code;
					$bw800->save($m);
				}
				$res=$bw800->add($bw800Model);
				
				
				
				echo $res;
			}
		}
	}
	
	public function deleteDevice(){
		$rid=I('rid');
		$type=I('type');
		
		$nm3000=M('nm3000');
		$bw800=M('bw800');
		$nm820=M('nm820');
		$nm410=M('nm410');
		if($type=='bw800'){
			$res= $bw800->delete($rid);
		}
		else if($type=='nm3000'){
			$res= $nm3000->delete($rid);
		}
		else if($type=='nm820'){
			$res= $nm820->delete($rid);
		}
		else if($type=='nm410'){
			$res= $nm410->delete($rid);
		}
		echo $res;
	}
	
	
	public function nm3000(){
		$rid = I("rid");
		$m=M('nm3000');
		$nm3000sltime=M('nm3000sltime');
		$nm3000xltime=M('nm3000xltime');
		
		$list = $m->where(" rid=".$rid)->select();
		//dump($list);
		$model=$list[0];
		$slmodel=$nm3000sltime->where(" lxcode='".$model['lxcode']."'")->select()[0];
		$xlmodel=$nm3000xltime->where(" lxcode='".$model['lxcode']."'")->select()[0];
		
		$this->assign('model',$model);
		$this->assign('slmodel',$slmodel);
		$this->assign('xlmodel',$xlmodel);
        $this->display('Setting:nm3000');
    }
	
	public function bw800(){
		$rid = I("rid");
		$bw800=M('bw800');
		$bw800cal=M('bw800caltable');
		$bw800time=M('bw800timetable');
		$bw800cc=M('bw800cctable');
		$bw800jc=M('bw800jctable');
		
		$list = $bw800->where(" rid=".$rid)->select();
		$bw800Model=$list[0];
		
		$bw800calList=$bw800cal->where(" lxcode='".$bw800Model['lxcode']."'")->select();
		$bw800timeList=$bw800time->where(" lxcode='".$bw800Model['lxcode']."'")->select();
		$bw800ccList=$bw800cc->where(" lxcode='".$bw800Model['lxcode']."'")->select();
		$bw800jcList=$bw800jc->where(" lxcode='".$bw800Model['lxcode']."'")->select();
		
		$this->assign('bw800Model',$bw800Model);
		$this->assign('bw800calList',$bw800calList);
		$this->assign('bw800timeList',$bw800timeList);
		$this->assign('bw800ccList',$bw800ccList);
		$this->assign('bw800jcList',$bw800jcList);
        $this->display('Setting:bw800');
    }
	
	public function nm820(){
		$rid = I("rid");
		$nm820=M('nm820');
		$nm820table=M('nm820table');
		
		$nm820Model = $nm820->where(" rid=".$rid)->find();
		
		$sensor_Wind=$nm820Model['sensor_wind'];
		$sensor_Wind_array=explode(',',$sensor_Wind);
		for($i=0;$i<count($sensor_Wind_array);$i++){
			$nm820Model['sensor_Wind'.($i+1)]=$sensor_Wind_array[$i];
		}
		
		$sensor_Channel=$nm820Model['sensor_channel'];
		$sensor_Channel_array=explode(',',$sensor_Channel);
		for($i=0;$i<count($sensor_Channel_array);$i++){
			$nm820Model['sensor_Channel'.($i+1)]=$sensor_Channel_array[$i];
		}
		$sensor_Cool=$nm820Model['sensor_cool'];
		$sensor_Cool_array=explode(',',$sensor_Cool);
		for($i=0;$i<count($sensor_Cool_array);$i++){
			$nm820Model['sensor_Cool'.($i+1)]=$sensor_Cool_array[$i];
		}
		$sensor_Spray=$nm820Model['sensor_spray'];
		$sensor_Spray_array=explode(',',$sensor_Spray);
		for($i=0;$i<count($sensor_Spray_array);$i++){
			$nm820Model['sensor_Spray'.($i+1)]=$sensor_Spray_array[$i];
		}
		
		$sensor_Heat=$nm820Model['sensor_heat'];
		$sensor_Heat_array=explode('|',$sensor_Heat);
		for($i=0;$i<count($sensor_Heat_array);$i++){
			$array=explode(',',$sensor_Heat_array[$i]);
			for($j=0;$j<count($array);$j++){
				$nm820Model['sensor_Heat'.($i+1).($j+1)]=$array[$j];
			}
		}
		
		$sensor_EX=$nm820Model['sensor_ex'];
		$sensor_EX_array=explode('|',$sensor_EX);
		for($i=0;$i<count($sensor_EX_array);$i++){
			$array=explode(',',$sensor_EX_array[$i]);
			for($j=0;$j<count($array);$j++){
				$nm820Model['sensor_EX'.($i+1).($j+1)]=$array[$j];
			}
		}
		
		$sys_Alarm_TempSF=$nm820Model['sys_alarm_tempsf'];
		$sys_Alarm_TempSF_array=explode(',',$sys_Alarm_TempSF);
		for($i=0;$i<count($sys_Alarm_TempSF_array);$i++){
			$nm820Model['sys_alarm_tempsf'.($i+1)]=$sys_Alarm_TempSF_array[$i];
		}
		
		$sys_Alarm_HumiSF=$nm820Model['sys_alarm_humisf'];
		$sys_Alarm_HumiSF_array=explode(',',$sys_Alarm_HumiSF);
		for($i=0;$i<count($sys_Alarm_HumiSF_array);$i++){
			$nm820Model['sys_alarm_humisf'.($i+1)]=$sys_Alarm_HumiSF_array[$i];
		}
		
		$sys_Time_Pos_ON=$nm820Model['sys_time_pos_on'];
		$sys_Time_Pos_ON_array=explode(',',$sys_Time_Pos_ON);
		for($i=0;$i<count($sys_Time_Pos_ON_array);$i++){
			$nm820Model['sys_Time_Pos_ON'.($i+1)]=$sys_Time_Pos_ON_array[$i];
		}
		
		$sys_Time_Pos_OFF=$nm820Model['sys_time_pos_off'];
		$sys_Time_Pos_OFF_array=explode(',',$sys_Time_Pos_OFF);
		for($i=0;$i<count($sys_Time_Pos_OFF_array);$i++){
			$nm820Model['sys_Time_Pos_OFF'.($i+1)]=$sys_Time_Pos_OFF_array[$i];
		}
		
		$cal_dTemp=$nm820Model['cal_dtemp'];
		$cal_dTemp_OFF_array=explode(',',$cal_dTemp);
		for($i=0;$i<count($cal_dTemp_OFF_array);$i++){
			$nm820Model['cal_dTemp'.($i+1)]=$cal_dTemp_OFF_array[$i];
		}
		
		$cal_dHumi=$nm820Model['cal_dhumi'];
		$cal_dHumi_array=explode(',',$cal_dHumi);
		for($i=0;$i<count($cal_dHumi_array);$i++){
			$nm820Model['cal_dHumi'.($i+1)]=$cal_dHumi_array[$i];
		}
		
		$cal_dHumi=$nm820Model['cal_dhumi'];
		$cal_dHumi_array=explode(',',$cal_dHumi);
		for($i=0;$i<count($cal_dHumi_array);$i++){
			$nm820Model['cal_dHumi'.($i+1)]=$cal_dHumi_array[$i];
		}
		//dump($nm820Model);
		
		//table
		$nm820tableModel = $nm820table->where(" code='".$nm820Model['code']."'")->find();
		
		$tempFig_Day=$nm820tableModel['tempfig_day'];
		$tempFig_Day_array=explode(',',$tempFig_Day);
		/* for($i=0;$i<count($tempFig_Day_array);$i++){
			$nm820tableModel['tempFig_Day'.($i+1)]=$tempFig_Day_array[$i];
		} */
		
		$tempFig_Target=$nm820tableModel['tempfig_target'];
		$tempFig_Target_array=explode(',',$tempFig_Target);
		/* for($i=0;$i<count($tempFig_Target_array);$i++){
			$nm820tableModel['tempFig_Target'.($i+1)]=$tempFig_Target_array[$i];
		} */
		
		$cool_Day=$nm820tableModel['cool_day'];
		$cool_Day_array=explode(',',$cool_Day);
		/* for($i=0;$i<count($cool_Day_array);$i++){
			$nm820tableModel['cool_Day'.($i+1)]=$cool_Day_array[$i];
		} */
		
		$cool_STime=$nm820tableModel['cool_stime'];
		$cool_STime_array=explode(',',$cool_STime);
		/* for($i=0;$i<count($cool_STime_array);$i++){
			$nm820tableModel['cool_STime'.($i+1)]=$cool_STime_array[$i];
		} */
		
		$cool_ETime=$nm820tableModel['cool_etime'];
		$cool_ETime_array=explode(',',$cool_ETime);
		/* for($i=0;$i<count($cool_ETime_array);$i++){
			$nm820tableModel['cool_ETime'.($i+1)]=$cool_ETime_array[$i];
		} */
		
		$cool_STemp=$nm820tableModel['cool_stemp'];
		$cool_STemp_array=explode(',',$cool_STemp);
		/* for($i=0;$i<count($cool_STemp_array);$i++){
			$nm820tableModel['cool_STemp'.($i+1)]=$cool_STemp_array[$i];
		} */
		
		$cool_EHumi=$nm820tableModel['cool_ehumi'];
		$cool_EHumi_array=explode(',',$cool_EHumi);
		/* for($i=0;$i<count($cool_EHumi_array);$i++){
			$nm820tableModel['cool_EHumi'.($i+1)]=$cool_EHumi_array[$i];
		} */
		
		$cool_On=$nm820tableModel['cool_on'];
		$cool_On_array=explode(',',$cool_On);
		/* for($i=0;$i<count($cool_On_array);$i++){
			$nm820tableModel['cool_On'.($i+1)]=$cool_On_array[$i];
		} */
		
		$cool_Off=$nm820tableModel['cool_off'];
		$cool_Off_array=explode(',',$cool_Off);
		/* for($i=0;$i<count($cool_Off_array);$i++){
			$nm820tableModel['cool_Off'.($i+1)]=$cool_Off_array[$i];
		} */
		
		$spray_Day=$nm820tableModel['spray_day'];
		$spray_Day_array=explode(',',$spray_Day);
		/* for($i=0;$i<count($spray_Day_array);$i++){
			$nm820tableModel['spray_Day'.($i+1)]=$spray_Day_array[$i];
		} */
		
		$spray_STime=$nm820tableModel['spray_stime'];
		$spray_STime_array=explode(',',$spray_STime);
		/* for($i=0;$i<count($spray_STime_array);$i++){
			$nm820tableModel['spray_STime'.($i+1)]=$spray_STime_array[$i];
		} */
		
		$spray_ETime=$nm820tableModel['spray_etime'];
		$spray_ETime_array=explode(',',$spray_ETime);
		/* for($i=0;$i<count($spray_ETime_array);$i++){
			$nm820tableModel['spray_ETime'.($i+1)]=$spray_ETime_array[$i];
		} */
		
		$spray_STemp=$nm820tableModel['spray_stemp'];
		$spray_STemp_array=explode(',',$spray_STemp);
		/*for($i=0;$i<count($spray_STemp_array);$i++){
			$nm820tableModel['spray_STemp'.($i+1)]=$spray_STemp_array[$i];
		}*/
		
		$spray_EHumi=$nm820tableModel['spray_ehumi'];
		$spray_EHumi_array=explode(',',$spray_EHumi);
		/*for($i=0;$i<count($spray_EHumi_array);$i++){
			$nm820tableModel['spray_EHumi'.($i+1)]=$spray_EHumi_array[$i];
		}*/
		
		$spray_On=$nm820tableModel['spray_on'];
		$spray_On_array=explode(',',$spray_On);
		/*for($i=0;$i<count($spray_On_array);$i++){
			$nm820tableModel['spray_On'.($i+1)]=$spray_On_array[$i];
		}*/
		
		$spray_Off=$nm820tableModel['spray_off'];
		$spray_Off_array=explode(',',$spray_Off);
		/* for($i=0;$i<count($spray_Off_array);$i++){
			$nm820tableModel['spray_Off'.($i+1)]=$spray_Off_array[$i];
		} */
		
		$heat_STime=$nm820tableModel['heat_stime'];
		$heat_STime_array=explode(',',$heat_STime);
		/*for($i=0;$i<count($heat_STime_array);$i++){
			$nm820tableModel['heat_STime'.($i+1)]=$heat_STime_array[$i];
		}*/
		
		$heat_ETime=$nm820tableModel['heat_etime'];
		$heat_ETime_array=explode(',',$heat_ETime);
		/*for($i=0;$i<count($heat_ETime_array);$i++){
			$nm820tableModel['heat_ETime'.($i+1)]=$heat_ETime_array[$i];
		}*/
		
		$heat_STemp=$nm820tableModel['heat_stemp'];
		$heat_STemp_array=explode(',',$heat_STemp);
		/*for($i=0;$i<count($heat_STemp_array);$i++){
			$nm820tableModel['heat_STemp'.($i+1)]=$heat_STemp_array[$i];
		}*/
		
		$heat_ETemp=$nm820tableModel['heat_etemp'];
		$heat_ETemp_array=explode(',',$heat_ETemp);
		/*for($i=0;$i<count($heat_ETemp_array);$i++){
			$nm820tableModel['heat_ETemp'.($i+1)]=$heat_ETemp_array[$i];
		}*/
		
		$heat_On=$nm820tableModel['heat_on'];
		$heat_On_array=explode(',',$heat_On);
		/*for($i=0;$i<count($heat_On_array);$i++){
			$nm820tableModel['heat_On'.($i+1)]=$heat_On_array[$i];
		}*/
		
		$heat_Off=$nm820tableModel['heat_off'];
		$heat_Off_array=explode(',',$heat_Off);
		/*for($i=0;$i<count($heat_Off_array);$i++){
			$nm820tableModel['heat_Off'.($i+1)]=$heat_Off_array[$i];
		}*/
		
		$light_STime=$nm820tableModel['light_stime'];
		$light_STime_array=explode(',',$light_STime);
		for($i=0;$i<count($light_STime_array);$i++){
			$nm820tableModel['light_STime'.($i+1)]=$light_STime_array[$i];
		}
		
		$light_ETime=$nm820tableModel['light_etime'];
		$light_ETime_array=explode(',',$light_ETime);
		for($i=0;$i<count($light_ETime_array);$i++){
			$nm820tableModel['light_ETime'.($i+1)]=$light_ETime_array[$i];
		}
		
		$light_Level=$nm820tableModel['light_level'];
		$light_Level_array=explode(',',$light_Level);
		for($i=0;$i<count($light_Level_array);$i++){
			$nm820tableModel['light_Level'.($i+1)]=$light_Level_array[$i];
		}
		
		$light_STime1=$nm820tableModel['light_stime1'];
		$light_STime1_array=explode(',',$light_STime1);
		for($i=0;$i<count($light_STime1_array);$i++){
			$nm820tableModel['light_STime1'.($i+1)]=$light_STime1_array[$i];
		}
		
		$light_STime2=$nm820tableModel['light_stime2'];
		$light_STime2_array=explode(',',$light_STime2);
		for($i=0;$i<count($light_STime2_array);$i++){
			$nm820tableModel['light_STime2'.($i+1)]=$light_STime2_array[$i];
		}
		
		$light_ETime1=$nm820tableModel['light_etime1'];
		$light_ETime1_array=explode(',',$light_ETime1);
		for($i=0;$i<count($light_ETime1_array);$i++){
			$nm820tableModel['light_ETime1'.($i+1)]=$light_ETime1_array[$i];
		}
		
		$light_ETime2=$nm820tableModel['light_etime2'];
		$light_ETime2_array=explode(',',$light_ETime2);
		for($i=0;$i<count($light_ETime2_array);$i++){
			$nm820tableModel['light_ETime2'.($i+1)]=$light_ETime2_array[$i];
		}
		
		//继电器编码
		$sys_Relay_array=explode(',',$nm820Model['sys_relay']);
		
		//通风级别
		$tongfen=array();
		$wind_On=$nm820tableModel['wind_on'];
		$wind_Off=$nm820tableModel['wind_off'];
		$wind_dTemp=$nm820tableModel['wind_dtemp'];
		$wind_Side=$nm820tableModel['wind_side'];
		$wind_Roller=$nm820tableModel['wind_roller'];
		$wind_VSFan=$nm820tableModel['wind_vsfan'];
		$wind_Top=$nm820tableModel['wind_top'];
		$wind_Slide=$nm820tableModel['wind_slide'];
		$wind_Fan=$nm820tableModel['wind_fan'];
		
		$wind_On_array=explode(',',$wind_On);
		$wind_Off_array=explode(',',$wind_Off);
		$wind_dTemp_array=explode(',',$wind_dTemp);
		$wind_Side_array=explode(',',$wind_Side);
		$wind_Roller_array=explode(',',$wind_Roller);
		$wind_VSFan_array=explode(',',$wind_VSFan);
		$wind_Top_array=explode(',',$wind_Top);
		$wind_Slide_array=explode(',',$wind_Slide);
		$wind_Fan_array=explode(',',$wind_Fan);
		//dump($wind_Fan_array);
		for($i=0;$i<count($wind_On_array);$i++){
			$m['index']=$i+1;
			$m['wind_On']=$wind_On_array[$i];
			$m['wind_Off']=$wind_Off_array[$i];
			$m['wind_dTemp']=$wind_dTemp_array[$i];
			$m['wind_Side']=$wind_Side_array[$i];
			$m['wind_Roller']=$wind_Roller_array[$i];
			$m['wind_VSFan']=$wind_VSFan_array[$i];
			$m['wind_Top']=$wind_Top_array[$i];
			$m['wind_Slide']=$wind_Slide_array[$i];
			$m['wind_Fan']=$wind_Fan_array[$i];
			
			//wind_Fan
			//dump($m['wind_Fan']);
			$wind_Fan_dec=$m['wind_Fan'];
			$bin=(string)decbin((int)$wind_Fan_dec);
			$bin=str_pad($bin,32,"0",STR_PAD_LEFT); //补0
			//dump($bin);
			for($j=15;$j>=0;$j--){
				$m['wind_Fan'.(16-$j)]=substr($bin,$j*2,2);
				
			}
			
			
			array_push($tongfen,$m);
		}
		
		//额外系统 3组
		$ex_STime=$nm820tableModel['ex_stime'];
		$ex_STime_array=explode(',',$ex_STime);
		for($i=0;$i<count($ex_STime_array);$i++){
			$nm820tableModel['ex_STime'.($i+1)]=$ex_STime_array[$i];
		}
		
		$ex_ETime=$nm820tableModel['ex_etime'];
		$ex_ETime_array=explode(',',$ex_ETime);
		for($i=0;$i<count($ex_ETime_array);$i++){
			$nm820tableModel['ex_ETime'.($i+1)]=$ex_ETime_array[$i];
		}
		
		$ex_STemp=$nm820tableModel['ex_stemp'];
		$ex_STemp_array=explode(',',$ex_STemp);
		for($i=0;$i<count($ex_STemp_array);$i++){
			$nm820tableModel['ex_STemp'.($i+1)]=$ex_STemp_array[$i];
		}
		
		$ex_ETemp=$nm820tableModel['ex_etemp'];
		$ex_ETemp_array=explode(',',$ex_ETemp);
		for($i=0;$i<count($ex_ETemp_array);$i++){
			$nm820tableModel['ex_ETemp'.($i+1)]=$ex_ETemp_array[$i];
		}
		
		$ex_On=$nm820tableModel['ex_on'];
		$ex_On_array=explode(',',$ex_On);
		for($i=0;$i<count($ex_On_array);$i++){
			$nm820tableModel['ex_On'.($i+1)]=$ex_On_array[$i];
		}
		
		$ex_Off=$nm820tableModel['ex_off'];
		$ex_Off_array=explode(',',$ex_Off);
		for($i=0;$i<count($ex_Off_array);$i++){
			$nm820tableModel['ex_Off'.($i+1)]=$ex_Off_array[$i];
		}
		
		//dump($sys_Relay_array);
		$this->assign('nm820Model',$nm820Model);
		$this->assign('nm820tableModel',$nm820tableModel);
		
		$this->assign('heat_STime_array',$heat_STime_array);
		$this->assign('heat_ETime_array',$heat_ETime_array);
		$this->assign('heat_STemp_array',$heat_STemp_array);
		$this->assign('heat_ETemp_array',$heat_ETemp_array);
		$this->assign('heat_On_array',$heat_On_array);
		$this->assign('heat_Off_array',$heat_Off_array);
		
		$this->assign('spray_Day_array',$spray_Day_array);
		$this->assign('spray_STime_array',$spray_STime_array);
		$this->assign('spray_ETime_array',$spray_ETime_array);
		$this->assign('spray_STemp_array',$spray_STemp_array);
		$this->assign('spray_EHumi_array',$spray_EHumi_array);
		$this->assign('spray_On_array',$spray_On_array);
		$this->assign('spray_Off_array',$spray_Off_array);
		
		$this->assign('cool_Day_array',$spray_Day_array);
		$this->assign('cool_STime_array',$cool_STime_array);
		$this->assign('cool_ETime_array',$cool_ETime_array);
		$this->assign('cool_STemp_array',$cool_STemp_array);
		$this->assign('cool_EHumi_array',$cool_EHumi_array);
		$this->assign('cool_On_array',$cool_On_array);
		$this->assign('cool_Off_array',$cool_Off_array);
		
		$this->assign('tempFig_Target_array',$tempFig_Target_array);
		$this->assign('tempFig_Day_array',$tempFig_Day_array);
		
		$this->assign('sys_Relay_array',$sys_Relay_array);
		$this->assign('tongfen',$tongfen);
        $this->display('Setting:nm820');
	}
	public function nm410()
	{
		$rid = I("rid");
		$nm410=M('nm410');
		$nm410table=M('nm410table');
		
		$nm410Model = $nm410->where(" rid=".$rid)->find();
		
		$sensor_Wind=$nm410Model['sensor_wind'];
		$sensor_Wind_array=explode(',',$sensor_Wind);
		for($i=0;$i<count($sensor_Wind_array);$i++){
			$nm410Model['sensor_Wind'.($i+1)]=$sensor_Wind_array[$i];
		}
		
		$sensor_Channel=$nm410Model['sensor_channel'];
		$sensor_Channel_array=explode(',',$sensor_Channel);
		for($i=0;$i<count($sensor_Channel_array);$i++){
			$nm410Model['sensor_Channel'.($i+1)]=$sensor_Channel_array[$i];
		}
		$sensor_Cool=$nm410Model['sensor_cool'];
		$sensor_Cool_array=explode(',',$sensor_Cool);
		for($i=0;$i<count($sensor_Cool_array);$i++){
			$nm410Model['sensor_Cool'.($i+1)]=$sensor_Cool_array[$i];
		}
		
		$sensor_Heat=$nm410Model['sensor_heat'];
		$sensor_Heat_array=explode('|',$sensor_Heat);
		for($i=0;$i<count($sensor_Heat_array);$i++){
			$array=explode(',',$sensor_Heat_array[$i]);
			for($j=0;$j<count($array);$j++){
				$nm410Model['sensor_Heat'.($i+1).($j+1)]=$array[$j];
			}
		}
		
		
		$sys_Alarm_TempSF=$nm410Model['sys_alarm_tempsf'];
		$sys_Alarm_TempSF_array=explode(',',$sys_Alarm_TempSF);
		for($i=0;$i<count($sys_Alarm_TempSF_array);$i++){
			$nm410Model['sys_alarm_tempsf'.($i+1)]=$sys_Alarm_TempSF_array[$i];
		}
		
		$sys_Alarm_HumiSF=$nm410Model['sys_alarm_humisf'];
		$sys_Alarm_HumiSF_array=explode(',',$sys_Alarm_HumiSF);
		for($i=0;$i<count($sys_Alarm_HumiSF_array);$i++){
			$nm410Model['sys_alarm_humisf'.($i+1)]=$sys_Alarm_HumiSF_array[$i];
		}
		
		$sys_Time_Pos_ON=$nm410Model['sys_time_pos_on'];
		$sys_Time_Pos_ON_array=explode(',',$sys_Time_Pos_ON);
		for($i=0;$i<count($sys_Time_Pos_ON_array);$i++){
			$nm410Model['sys_Time_Pos_ON'.($i+1)]=$sys_Time_Pos_ON_array[$i];
		}
		
		$sys_Time_Pos_OFF=$nm410Model['sys_time_pos_off'];
		$sys_Time_Pos_OFF_array=explode(',',$sys_Time_Pos_OFF);
		for($i=0;$i<count($sys_Time_Pos_OFF_array);$i++){
			$nm410Model['sys_Time_Pos_OFF'.($i+1)]=$sys_Time_Pos_OFF_array[$i];
		}
		
		$cal_dTemp=$nm410Model['cal_dtemp'];
		$cal_dTemp_array=explode(',',$cal_dTemp);
		for($i=0;$i<count($cal_dTemp_array);$i++){
			$nm410Model['cal_dTemp'.($i+1)]=$cal_dTemp_array[$i];
		}
		
		$cal_dHumi=$nm410Model['cal_dhumi'];
		$cal_dHumi_array=explode(',',$cal_dHumi);
		for($i=0;$i<count($cal_dHumi_array);$i++){
			$nm410Model['cal_dHumi'.($i+1)]=$cal_dHumi_array[$i];
		}
		
		//table
		$nm410tableModel = $nm410table->where(" code='".$nm410Model['code']."'")->find();
		
		$tempFig_Day=$nm410tableModel['tempfig_day'];
		$tempFig_Day_array=explode(',',$tempFig_Day);
		
		$tempFig_Target=$nm410tableModel['tempfig_target'];
		$tempFig_Target_array=explode(',',$tempFig_Target);
		
		$cool_Day=$nm410tableModel['cool_day'];
		$cool_Day_array=explode(',',$cool_Day);
		
		$cool_STime=$nm410tableModel['cool_stime'];
		$cool_STime_array=explode(',',$cool_STime);
		
		$cool_ETime=$nm410tableModel['cool_etime'];
		$cool_ETime_array=explode(',',$cool_ETime);
		
		$cool_STemp=$nm410tableModel['cool_stemp'];
		$cool_STemp_array=explode(',',$cool_STemp);
		
		$cool_EHumi=$nm410tableModel['cool_ehumi'];
		$cool_EHumi_array=explode(',',$cool_EHumi);
		
		$cool_On=$nm410tableModel['cool_on'];
		$cool_On_array=explode(',',$cool_On);
		
		$cool_Off=$nm410tableModel['cool_off'];
		$cool_Off_array=explode(',',$cool_Off);
		
		$heat_STime=$nm410tableModel['heat_stime'];
		$heat_STime_array=explode(',',$heat_STime);
		
		$heat_ETime=$nm410tableModel['heat_etime'];
		$heat_ETime_array=explode(',',$heat_ETime);
		
		$heat_STemp=$nm410tableModel['heat_stemp'];
		$heat_STemp_array=explode(',',$heat_STemp);
		
		$heat_ETemp=$nm410tableModel['heat_etemp'];
		$heat_ETemp_array=explode(',',$heat_ETemp);
		
		$heat_On=$nm410tableModel['heat_on'];
		$heat_On_array=explode(',',$heat_On);
		
		$heat_Off=$nm410tableModel['heat_off'];
		$heat_Off_array=explode(',',$heat_Off);
		
		$light_STime=$nm410tableModel['light_stime'];
		$light_STime_array=explode(',',$light_STime);
		for($i=0;$i<count($light_STime_array);$i++){
			$nm410tableModel['light_STime'.($i+1)]=$light_STime_array[$i];
		}
		
		$light_ETime=$nm410tableModel['light_etime'];
		$light_ETime_array=explode(',',$light_ETime);
		for($i=0;$i<count($light_ETime_array);$i++){
			$nm410tableModel['light_ETime'.($i+1)]=$light_ETime_array[$i];
		}
		
		$light_Level=$nm410tableModel['light_level'];
		$light_Level_array=explode(',',$light_Level);
		for($i=0;$i<count($light_Level_array);$i++){
			$nm410tableModel['light_Level'.($i+1)]=$light_Level_array[$i];
		}
		
		$light_STime1=$nm410tableModel['light_stime1'];
		$light_STime1_array=explode(',',$light_STime1);
		for($i=0;$i<count($light_STime1_array);$i++){
			$nm410tableModel['light_STime1'.($i+1)]=$light_STime1_array[$i];
		}
		
		$light_ETime1=$nm410tableModel['light_etime1'];
		$light_ETime1_array=explode(',',$light_ETime1);
		for($i=0;$i<count($light_ETime1_array);$i++){
			$nm410tableModel['light_ETime1'.($i+1)]=$light_ETime1_array[$i];
		}
		
		//继电器编码
		$sys_Relay_array=explode(',',$nm410Model['sys_relay']);
		
		//通风级别
		$tongfen=array();
		$wind_On=$nm410tableModel['wind_on'];
		$wind_Off=$nm410tableModel['wind_off'];
		$wind_dTemp=$nm410tableModel['wind_dtemp'];
		$wind_Side=$nm410tableModel['wind_side'];
		$wind_Roller=$nm410tableModel['wind_roller'];
		$wind_VSFan=$nm410tableModel['wind_vsfan'];
		$wind_Top=$nm410tableModel['wind_top'];
		$wind_Slide=$nm410tableModel['wind_slide'];
		$wind_Fan=$nm410tableModel['wind_fan'];
		
		$wind_On_array=explode(',',$wind_On);
		$wind_Off_array=explode(',',$wind_Off);
		$wind_dTemp_array=explode(',',$wind_dTemp);
		$wind_Side_array=explode(',',$wind_Side);
		$wind_Roller_array=explode(',',$wind_Roller);
		$wind_VSFan_array=explode(',',$wind_VSFan);
		$wind_Top_array=explode(',',$wind_Top);
		$wind_Slide_array=explode(',',$wind_Slide);
		$wind_Fan_array=explode(',',$wind_Fan);
		//dump($wind_Fan_array);
		for($i=0;$i<count($wind_On_array);$i++){
			$m['index']=$i+1;
			$m['wind_On']=$wind_On_array[$i];
			$m['wind_Off']=$wind_Off_array[$i];
			$m['wind_dTemp']=$wind_dTemp_array[$i];
			$m['wind_Side']=$wind_Side_array[$i];
			$m['wind_Roller']=$wind_Roller_array[$i];
			$m['wind_VSFan']=$wind_VSFan_array[$i];
			$m['wind_Top']=$wind_Top_array[$i];
			$m['wind_Slide']=$wind_Slide_array[$i];
			$m['wind_Fan']=$wind_Fan_array[$i];
			
			//wind_Fan
			//dump($m['wind_Fan']);
			$wind_Fan_dec=$m['wind_Fan'];
			$bin=(string)decbin((int)$wind_Fan_dec);
			$bin=str_pad($bin,16,"0",STR_PAD_LEFT); //补0
			//dump($bin);
			for($j=7;$j>=0;$j--){
				$m['wind_Fan'.(8-$j)]=substr($bin,$j*2,2);
				
			}
			
			
			array_push($tongfen,$m);
		}
		
		//dump($sys_Relay_array);
		$this->assign('nm410Model',$nm410Model);
		$this->assign('nm410tableModel',$nm410tableModel);
		
		$this->assign('heat_STime_array',$heat_STime_array);
		$this->assign('heat_ETime_array',$heat_ETime_array);
		$this->assign('heat_STemp_array',$heat_STemp_array);
		$this->assign('heat_ETemp_array',$heat_ETemp_array);
		$this->assign('heat_On_array',$heat_On_array);
		$this->assign('heat_Off_array',$heat_Off_array);
		
		
		$this->assign('cool_Day_array',$cool_Day_array);
		$this->assign('cool_STime_array',$cool_STime_array);
		$this->assign('cool_ETime_array',$cool_ETime_array);
		$this->assign('cool_STemp_array',$cool_STemp_array);
		$this->assign('cool_EHumi_array',$cool_EHumi_array);
		$this->assign('cool_On_array',$cool_On_array);
		$this->assign('cool_Off_array',$cool_Off_array);
		
		$this->assign('tempFig_Target_array',$tempFig_Target_array);
		$this->assign('tempFig_Day_array',$tempFig_Day_array);
		
		$this->assign('sys_Relay_array',$sys_Relay_array);
		$this->assign('tongfen',$tongfen);
        $this->display('Setting:nm410');
	}
	
	//nm820
	public function save820(){
		$p['rid'] = I("get.rid");
		$p['code'] = I("code");
		
		$p['mh_Day'] = I("mh_Day");
		$p['mh_DeadTotal'] = I("mh_DeadTotal");
		$p['mh_SerNum'] = I("mh_SerNum");
		$p['mh_InitNum'] = I("mh_InitNum");
		$p['mh_RevNum'] = I("mh_RevNum");
		
		$p['serverIP'] = I("serverIP");
		$p['serverPort'] = I("serverPort");
		$p['localIP'] = I("localIP");
		$p['gateway'] = I("gateway");
		$p['netmask'] = I("netmask");
		
		$p['tunnel_Temp'] = I("tunnel_Temp");
		$p['sys_Level_StartChannel'] = I("sys_Level_StartChannel");
		$p['sys_Time_Channel'] = I("sys_Time_Channel");
		
		$p['humi_Target'] = I("humi_Target");
		$p['humi_Max'] = I("humi_Max");
		$p['humi_Min'] = I("humi_Min");
		
		$p['nh3_Max'] = I("nh3_Max");
		$p['nh3_dVal'] = I("nh3_dVal");
		
		$sensor_Wind=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Wind".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Wind,$value);
		}
		$p['sensor_Wind'] = join(',',$sensor_Wind);
		
		$sensor_Channel=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Channel".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Channel,$value);
		}
		$p['sensor_Channel'] = join(',',$sensor_Channel);
		
		$sensor_Cool=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Cool".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Cool,$value);
		}
		$p['sensor_Cool'] = join(',',$sensor_Cool);
		
		$sensor_Spray=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Spray".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Spray,$value);
		}
		$p['sensor_Spray'] = join(',',$sensor_Spray);
		
		$sensor_Heat=array();
		for($x=0;$x<6;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_Heat".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_Heat,join(',',$tm));
		}
		$p['sensor_Heat'] = join('|',$sensor_Heat);
		
		$sensor_EX=array();
		for($x=0;$x<3;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_EX".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_EX,join(',',$tm));
		}
		$p['sensor_EX'] = join('|',$sensor_EX);
		
		$p['sys_Delay_FanUp'] = I("sys_Delay_FanUp");
		$p['sys_Delay_FanDown'] = I("sys_Delay_FanDown");
		$p['sys_Delay_HumiUp'] = I("sys_Delay_HumiUp");
		$p['sys_Delay_HumiRst'] = I("sys_Delay_HumiRst");
		$p['sys_Delay_NH3Up'] = I("sys_Delay_NH3Up");
		$p['sys_Delay_NH3Rst'] = I("sys_Delay_NH3Rst");
		$p['sys_Delay_OTemp'] = I("sys_Delay_OTemp");
		$p['sys_Delay_OTempRst'] = I("sys_Delay_OTempRst");
		$p['sys_dTemp_OTemp'] = I("sys_dTemp_OTemp");
		
		$sys_Time_Pos_ON=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_ON,I("sys_Time_Pos_ON".($i+1)));
		}
		$p['sys_Time_Pos_ON'] = join(',',$sys_Time_Pos_ON);
		
		$sys_Time_Pos_OFF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_OFF,I("sys_Time_Pos_OFF".($i+1)));
		}
		$p['sys_Time_Pos_OFF'] = join(',',$sys_Time_Pos_OFF);
		
		$p['sys_Delay_Return'] = I("sys_Delay_Return");
		$p['sys_Is_LimitLevel'] = I("sys_Is_LimitLevel");
		$p['sys_MaxLevel'] = I("sys_MaxLevel");
		$p['sys_Is_LevelUp_Humi'] = I("sys_Is_LevelUp_Humi");
		$p['sys_Is_LevelUp_NH3'] = I("sys_Is_LevelUp_NH3");
		$p['sys_Is_LevelUp_OTemp'] = I("sys_Is_LevelUp_OTemp");
		$p['sys_LevelUp_Max'] = I("sys_LevelUp_Max");
		
		$sys_Alarm_TempSF=array();
		for($i=0;$i<8;$i++){
			array_push($sys_Alarm_TempSF,I("sys_Alarm_TempSF".($i+1)));
		}
		$p['sys_Alarm_TempSF'] = join(',',$sys_Alarm_TempSF);
		
		$sys_Alarm_HumiSF=array();
		for($i=0;$i<2;$i++){
			array_push($sys_Alarm_HumiSF,I("sys_Alarm_HumiSF".($i+1)));
		}
		$p['sys_Alarm_HumiSF'] = join(',',$sys_Alarm_HumiSF);
		

		$p['sys_Alarm_LightSF'] = I("sys_Alarm_LightSF");
		$p['sys_Alarm_NH3'] = I("sys_Alarm_NH3");
		$p['sys_Alarm_Temp_Max'] = I("sys_Alarm_Temp_Max");
		$p['sys_Alarm_Temp_Min'] = I("sys_Alarm_Temp_Min");
		$p['sys_Alarm_dTemp_Max'] = I("sys_Alarm_dTemp_Max");
		$p['sys_Alarm_dTemp_Min'] = I("sys_Alarm_dTemp_Min");
		$p['sys_Alarm_Humi_Max'] = I("sys_Alarm_Humi_Max");
		$p['sys_Alarm_Humi_Min'] = I("sys_Alarm_Humi_Min");
		$p['sys_Alarm_Light_Min'] = I("sys_Alarm_Light_Min");
		$p['sys_Alarm_NH3_Max'] = I("sys_Alarm_NH3_Max");
		$p['sys_Password'] = I("sys_Password");
		//$p['sys_Relay'] = I("sys_Relay");
		$sys_Relay=array();
		for($i=1;$i<29;$i++){
			array_push($sys_Relay,I("sys_Relay".($i)));
		}
		$p['sys_Relay'] = join(',',$sys_Relay);
		//dump($p['sys_Relay']);
		$p['version'] = I("version");
		
		$p['sys_Mode'] = I("sys_Mode");
		
		//校准
		$cal_dTemp=array();
		for($i=0;$i<8;$i++){
			$value=I("cal_dTemp".($i+1));
			array_push($cal_dTemp,$value);
		}
		$p['cal_dTemp'] = join(',',$cal_dTemp);
		$cal_dHumi=array();
		for($i=0;$i<2;$i++){
			$value=I("cal_dHumi".($i+1));
			array_push($cal_dHumi,$value);
		}
		$p['cal_dHumi'] = join(',',$cal_dHumi);
		$p['cal_dLight'] = I("cal_dLight");
		$p['cal_dNH3'] = I("cal_dNH3");
		$p['cal_PulseWater'] = I("cal_PulseWater");
		
		
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		
		//-----------------------------------------------------------------------------------------------分割线-------------------------------------------------------------------------
		$tempFig_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("tempFig_Day".($i+1));
			array_push($tempFig_Day,$value);
		}
		$p1['tempFig_Day'] = join(',',$tempFig_Day);
		
		$tempFig_Target=array();
		for($i=0;$i<11;$i++){
			$value=I("tempFig_Target".($i+1));
			array_push($tempFig_Target,$value);
		}
		$p1['tempFig_Target'] = join(',',$tempFig_Target);
		
		$cool_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Day".($i+1));
			array_push($cool_Day,$value);
		}
		$p1['cool_Day'] = join(',',$cool_Day);
		
		$cool_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STime".($i+1));
			array_push($cool_STime,$value);
		}
		$p1['cool_STime'] = join(',',$cool_STime);
		
		$cool_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_ETime".($i+1));
			array_push($cool_ETime,$value);
		}
		$p1['cool_ETime'] = join(',',$cool_ETime);
		
		$cool_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STemp".($i+1));
			array_push($cool_STemp,$value);
		}
		$p1['cool_STemp'] = join(',',$cool_STemp);
		
		$cool_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_EHumi".($i+1));
			array_push($cool_EHumi,$value);
		}
		$p1['cool_EHumi'] = join(',',$cool_EHumi);
		
		$cool_On=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_On".($i+1));
			array_push($cool_On,$value);
		}
		$p1['cool_On'] = join(',',$cool_On);
		
		$cool_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Off".($i+1));
			array_push($cool_Off,$value);
		}
		$p1['cool_Off'] = join(',',$cool_Off);
		
		$spray_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_Day".($i+1));
			array_push($spray_Day,$value);
		}
		$p1['spray_Day'] = join(',',$spray_Day);
		
		$spray_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_STime".($i+1));
			array_push($spray_STime,$value);
		}
		$p1['spray_STime'] = join(',',$spray_STime);
		
		$spray_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_ETime".($i+1));
			array_push($spray_ETime,$value);
		}
		$p1['spray_ETime'] = join(',',$spray_ETime);
		
		$spray_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_STemp".($i+1));
			array_push($spray_STemp,$value);
		}
		$p1['spray_STemp'] = join(',',$spray_STemp);
		
		$spray_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_EHumi".($i+1));
			array_push($spray_EHumi,$value);
		}
		$p1['spray_EHumi'] = join(',',$spray_EHumi);
		
		$spray_On=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_On".($i+1));
			array_push($spray_On,$value);
		}
		$p1['spray_On'] = join(',',$spray_On);
		
		$spray_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_Off".($i+1));
			array_push($spray_Off,$value);
		}
		$p1['spray_Off'] = join(',',$spray_Off);
		
		$heat_STime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STime".($i+1));
			array_push($heat_STime,$value);
		}
		$p1['heat_STime'] = join(',',$heat_STime);
		
		$heat_ETime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETime".($i+1));
			array_push($heat_ETime,$value);
		}
		$p1['heat_ETime'] = join(',',$heat_ETime);
		
		$heat_STemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STemp".($i+1));
			array_push($heat_STemp,$value);
		}
		$p1['heat_STemp'] = join(',',$heat_STemp);
		
		$heat_ETemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETemp".($i+1));
			array_push($heat_ETemp,$value);
		}
		$p1['heat_ETemp'] = join(',',$heat_ETemp);
		
		$heat_On=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_On".($i+1));
			array_push($heat_On,$value);
		}
		$p1['heat_On'] = join(',',$heat_On);
		
		$heat_Off=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_Off".($i+1));
			array_push($heat_Off,$value);
		}
		$p1['heat_Off'] = join(',',$heat_Off);
		
		$light_STime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime".($i+1));
			array_push($light_STime,$value);
		}
		$p1['light_STime'] = join(',',$light_STime);
		
		$light_ETime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime".($i+1));
			array_push($light_ETime,$value);
		}
		$p1['light_ETime'] = join(',',$light_ETime);
		
		$light_Level=array();
		for($i=0;$i<5;$i++){
			$value=I("light_Level".($i+1));
			array_push($light_Level,$value);
		}
		$p1['light_Level'] = join(',',$light_Level);
		
		$light_STime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime1".($i+1));
			array_push($light_STime1,$value);
		}
		$p1['light_STime1'] = join(',',$light_STime1);
		
		$light_STime2=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime2".($i+1));
			array_push($light_STime2,$value);
		}
		$p1['light_STime2'] = join(',',$light_STime2);
		
		$light_ETime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime1".($i+1));
			array_push($light_ETime1,$value);
		}
		$p1['light_ETime1'] = join(',',$light_ETime1);
		
		$light_ETime2=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime2".($i+1));
			array_push($light_ETime2,$value);
		}
		$p1['light_ETime2'] = join(',',$light_ETime2);
		
		$wind_On=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_On".($i+1));
			array_push($wind_On,$value);
		}
		$p1['wind_On'] = join(',',$wind_On);
		
		$wind_Off=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Off".($i+1));
			array_push($wind_Off,$value);
		}
		$p1['wind_Off'] = join(',',$wind_Off);
		
		$wind_dTemp=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_dTemp".($i+1));
			array_push($wind_dTemp,$value);
		}
		$p1['wind_dTemp'] = join(',',$wind_dTemp);
		
		$wind_Side=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Side".($i+1));
			array_push($wind_Side,$value);
		}
		$p1['wind_Side'] = join(',',$wind_Side);
		
		$wind_Roller=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Roller".($i+1));
			array_push($wind_Roller,$value);
		}
		$p1['wind_Roller'] = join(',',$wind_Roller);
		
		$wind_VSFan=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_VSFan".($i+1));
			array_push($wind_VSFan,$value);
		}
		$p1['wind_VSFan'] = join(',',$wind_VSFan);
		
		$wind_Top=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Top".($i+1));
			array_push($wind_Top,$value);
		}
		$p1['wind_Top'] = join(',',$wind_Top);
		
		$wind_Slide=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Slide".($i+1));
			array_push($wind_Slide,$value);
		}
		$p1['wind_Slide'] = join(',',$wind_Slide);
		
		$wind_Fan=array();
		for($i=0;$i<40;$i++){
			$value='';
			for($j=16;$j>0;$j--){
				$t=I("wind_Fan".($j)."_".($i+1));
				$value.=$t;
			}
			array_push($wind_Fan,(string)bindec($value));
		}
		$p1['wind_Fan'] = join(',',$wind_Fan);
		
		//额外系统 3组
		$ex_STime=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_STime".($i+1));
			//$value='00:00';
			array_push($ex_STime,$value);
		}
		$p1['ex_STime'] =join(',',$ex_STime);
		
		$ex_ETime=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_ETime".($i+1));
			//$value='00:00';
			array_push($ex_ETime,$value);
		}
		$p1['ex_ETime'] =join(',',$ex_ETime);
		
		$ex_STemp=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_STemp".($i+1));
			//$value='0.0';
			array_push($ex_STemp,$value);
		}
		$p1['ex_STemp'] =join(',',$ex_STemp);
		
		$ex_ETemp=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_ETemp".($i+1));
			//$value='0.0';
			array_push($ex_ETemp,$value);
		}
		$p1['ex_ETemp'] =join(',',$ex_ETemp);
		
		$ex_On=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_On".($i+1));
			//$value='0.0';
			array_push($ex_On,$value);
		}
		$p1['ex_On'] =join(',',$ex_On);
		
		$ex_Off=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_Off".($i+1));
			//$value='0.0';
			array_push($ex_Off,$value);
		}
		$p1['ex_Off'] =join(',',$ex_Off);
		
		$nm820table=M('nm820table');
		$res= $nm820table->where(" code=".$p['code'])->save($p1);
		echo $res;
	}
	public function save410(){
		$p['rid'] = I("get.rid");
		$p['code'] = I("code");
		
		//统计
		$p['mh_Day'] = I("mh_Day");
		$p['mh_DeadTotal'] = I("mh_DeadTotal");
		$p['mh_InitNum'] = I("mh_InitNum");
		$p['mh_RevNum'] = I("mh_RevNum");
		//通信
		$p['serverIP'] = I("serverIP");
		$p['serverPort'] = I("serverPort");
		$p['localIP'] = I("localIP");
		$p['gateway'] = I("gateway");
		$p['netmask'] = I("netmask");
		//隧道设置
		$p['tunnel_Temp'] = I("tunnel_Temp");
		$p['sys_Level_StartChannel'] = I("sys_Level_StartChannel");
		$p['sys_Time_Channel'] = I("sys_Time_Channel");
		//传感器
		$sensor_Wind=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Wind".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Wind,$value);
		}
		$p['sensor_Wind'] = join(',',$sensor_Wind);
		
		$sensor_Channel=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Channel".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Channel,$value);
		}
		$p['sensor_Channel'] = join(',',$sensor_Channel);
		
		$sensor_Cool=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Cool".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Cool,$value);
		}
		$p['sensor_Cool'] = join(',',$sensor_Cool);
		
		$sensor_Heat=array();
		for($x=0;$x<3;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_Heat".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_Heat,join(',',$tm));
		}
		$p['sensor_Heat'] = join('|',$sensor_Heat);
		
		$p['sys_Delay_FanUp'] = I("sys_Delay_FanUp");
		$p['sys_Delay_FanDown'] = I("sys_Delay_FanDown");
		$sys_Time_Pos_ON=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_ON,I("sys_Time_Pos_ON".($i+1)));
		}
		$p['sys_Time_Pos_ON'] = join(',',$sys_Time_Pos_ON);
		
		$sys_Time_Pos_OFF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_OFF,I("sys_Time_Pos_OFF".($i+1)));
		}
		$p['sys_Time_Pos_OFF'] = join(',',$sys_Time_Pos_OFF);
		
		$sys_Alarm_TempSF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Alarm_TempSF,I("sys_Alarm_TempSF".($i+1)));
		}
		$p['sys_Alarm_TempSF'] = join(',',$sys_Alarm_TempSF);
		
		$sys_Alarm_HumiSF=array();
		for($i=0;$i<1;$i++){
			array_push($sys_Alarm_HumiSF,I("sys_Alarm_HumiSF".($i+1)));
		}
		$p['sys_Alarm_HumiSF'] = join(',',$sys_Alarm_HumiSF);

		$p['sys_EnHumi'] = I("sys_EnHumi");
		$p['sys_Alarm_Temp_Max'] = I("sys_Alarm_Temp_Max");
		$p['sys_Alarm_Temp_Min'] = I("sys_Alarm_Temp_Min");
		$p['sys_Alarm_Humi_Max'] = I("sys_Alarm_Humi_Max");
		$p['sys_Alarm_Humi_Min'] = I("sys_Alarm_Humi_Min");

		$sys_Relay=array();
		for($i=1;$i<17;$i++){
			array_push($sys_Relay,I("sys_Relay".($i)));
		}
		$p['sys_Relay'] = join(',',$sys_Relay);
		$p['sys_Mode'] = I("sys_Mode");
		
		//$p['sys_Password'] = I("sys_Password");//密码
		
		//校准
		$cal_dTemp=array();
		for($i=0;$i<4;$i++){
			$value=I("cal_dTemp".($i+1));
			array_push($cal_dTemp,$value);
		}
		$p['cal_dTemp'] = join(',',$cal_dTemp);
		$cal_dHumi=array();
		for($i=0;$i<1;$i++){
			$value=I("cal_dHumi".($i+1));
			array_push($cal_dHumi,$value);
		}
		$p['cal_dHumi'] = join(',',$cal_dHumi);
		
		$nm410=M('nm410');
		//dump($p);
		$res= $nm410->where(" rid=".$p['rid'])->save($p);
		
		//-----------------------------------------------------------------------------------------------分割线-------------------------------------------------------------------------
		$tempFig_Day=array();
		for($i=0;$i<8;$i++){
			$value=I("tempFig_Day".($i+1));
			array_push($tempFig_Day,$value);
		}
		$p1['tempFig_Day'] = join(',',$tempFig_Day);
		
		$tempFig_Target=array();
		for($i=0;$i<8;$i++){
			$value=I("tempFig_Target".($i+1));
			array_push($tempFig_Target,$value);
		}
		$p1['tempFig_Target'] = join(',',$tempFig_Target);
		

		$cool_Day=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_Day".($i+1));
			array_push($cool_Day,$value);
		}
		$p1['cool_Day'] = join(',',$cool_Day);
		
		$cool_STime=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_STime".($i+1));
			array_push($cool_STime,$value);
		}
		$p1['cool_STime'] = join(',',$cool_STime);
		
		$cool_ETime=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_ETime".($i+1));
			array_push($cool_ETime,$value);
		}
		$p1['cool_ETime'] = join(',',$cool_ETime);
		
		$cool_STemp=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_STemp".($i+1));
			array_push($cool_STemp,$value);
		}
		$p1['cool_STemp'] = join(',',$cool_STemp);
		
		$cool_EHumi=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_EHumi".($i+1));
			array_push($cool_EHumi,$value);
		}
		$p1['cool_EHumi'] = join(',',$cool_EHumi);
		
		$cool_On=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_On".($i+1));
			array_push($cool_On,$value);
		}
		$p1['cool_On'] = join(',',$cool_On);
		
		$cool_Off=array();
		for($i=0;$i<1;$i++){
			$value=I("cool_Off".($i+1));
			array_push($cool_Off,$value);
		}
		$p1['cool_Off'] = join(',',$cool_Off);
		
		
		
		$heat_STime=array();
		for($i=0;$i<3;$i++){
			$value=I("heat_STime".($i+1));
			array_push($heat_STime,$value);
		}
		$p1['heat_STime'] = join(',',$heat_STime);
		
		$heat_ETime=array();
		for($i=0;$i<3;$i++){
			$value=I("heat_ETime".($i+1));
			array_push($heat_ETime,$value);
		}
		$p1['heat_ETime'] = join(',',$heat_ETime);
		
		$heat_STemp=array();
		for($i=0;$i<3;$i++){
			$value=I("heat_STemp".($i+1));
			array_push($heat_STemp,$value);
		}
		$p1['heat_STemp'] = join(',',$heat_STemp);
		
		$heat_ETemp=array();
		for($i=0;$i<3;$i++){
			$value=I("heat_ETemp".($i+1));
			array_push($heat_ETemp,$value);
		}
		$p1['heat_ETemp'] = join(',',$heat_ETemp);
		
		$heat_On=array();
		for($i=0;$i<3;$i++){
			$value=I("heat_On".($i+1));
			array_push($heat_On,$value);
		}
		$p1['heat_On'] = join(',',$heat_On);
		
		$heat_Off=array();
		for($i=0;$i<3;$i++){
			$value=I("heat_Off".($i+1));
			array_push($heat_Off,$value);
		}
		$p1['heat_Off'] = join(',',$heat_Off);
		
		$light_STime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime".($i+1));
			array_push($light_STime,$value);
		}
		$p1['light_STime'] = join(',',$light_STime);
		
		$light_ETime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime".($i+1));
			array_push($light_ETime,$value);
		}
		$p1['light_ETime'] = join(',',$light_ETime);
		
		$light_Level=array();
		for($i=0;$i<5;$i++){
			$value=I("light_Level".($i+1));
			array_push($light_Level,$value);
		}
		$p1['light_Level'] = join(',',$light_Level);
		
		$light_STime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime1".($i+1));
			array_push($light_STime1,$value);
		}
		$p1['light_STime1'] = join(',',$light_STime1);

		$light_ETime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime1".($i+1));
			array_push($light_ETime1,$value);
		}
		$p1['light_ETime1'] = join(',',$light_ETime1);

		
		$wind_On=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_On".($i+1));
			array_push($wind_On,$value);
		}
		$p1['wind_On'] = join(',',$wind_On);
		
		$wind_Off=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Off".($i+1));
			array_push($wind_Off,$value);
		}
		$p1['wind_Off'] = join(',',$wind_Off);
		
		$wind_dTemp=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_dTemp".($i+1));
			array_push($wind_dTemp,$value);
		}
		$p1['wind_dTemp'] = join(',',$wind_dTemp);
		
		$wind_Side=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Side".($i+1));
			array_push($wind_Side,$value);
		}
		$p1['wind_Side'] = join(',',$wind_Side);
		
		$wind_Roller=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Roller".($i+1));
			array_push($wind_Roller,$value);
		}
		$p1['wind_Roller'] = join(',',$wind_Roller);
		
		$wind_VSFan=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_VSFan".($i+1));
			array_push($wind_VSFan,$value);
		}
		$p1['wind_VSFan'] = join(',',$wind_VSFan);
		
		$wind_Top=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Top".($i+1));
			array_push($wind_Top,$value);
		}
		$p1['wind_Top'] = join(',',$wind_Top);
		
		$wind_Slide=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Slide".($i+1));
			array_push($wind_Slide,$value);
		}
		$p1['wind_Slide'] = join(',',$wind_Slide);
		
		$wind_Fan=array();
		for($i=0;$i<20;$i++){
			$value='';
			for($j=8;$j>0;$j--){
				$t=I("wind_Fan".($j)."_".($i+1));
				$value.=$t;
			}
			array_push($wind_Fan,(string)bindec($value));
		}
		$p1['wind_Fan'] = join(',',$wind_Fan);
		
		$nm410table=M('nm410table');
		$res= $nm410table->where(" code=".$p['code'])->save($p1);
		echo $res;
	}
	
	public function save820tongji()
	{
		$p['rid'] = I("get.rid");
		//$p['code'] = I("code");
		$p['mh_Day'] = I("mh_Day");
		$p['mh_DeadTotal'] = I("mh_DeadTotal");
		$p['mh_SerNum'] = I("mh_SerNum");
		$p['mh_InitNum'] = I("mh_InitNum");
		$p['mh_RevNum'] = I("mh_RevNum");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820net()
	{
		$p['rid'] = I("get.rid");
		$p['code'] = I("code");
		$p['serverIP'] = I("serverIP");
		$p['serverPort'] = I("serverPort");
		$p['localIP'] = I("localIP");
		$p['gateway'] = I("gateway");
		$p['netmask'] = I("netmask");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820channel()
	{
		$p['rid'] = I("get.rid");
		//$p['code'] = I("code");
		$p['tunnel_Temp'] = I("tunnel_Temp");
		$p['sys_Level_StartChannel'] = I("sys_Level_StartChannel");
		$p['sys_Time_Channel'] = I("sys_Time_Channel");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820humi()
	{
		$p['rid'] = I("get.rid");
		//$p['code'] = I("code");
		$p['humi_Target'] = I("humi_Target");
		$p['humi_Max'] = I("humi_Max");
		$p['humi_Min'] = I("humi_Min");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820nh3()
	{
		$p['rid'] = I("get.rid");
		//$p['code'] = I("code");
		$p['nh3_Max'] = I("nh3_Max");
		$p['nh3_dVal'] = I("nh3_dVal");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820sensor()
	{
		$p['rid'] = I("get.rid");
		$sensor_Wind=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Wind".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Wind,$value);
		}
		$p['sensor_Wind'] = join(',',$sensor_Wind);
		
		$sensor_Channel=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Channel".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Channel,$value);
		}
		$p['sensor_Channel'] = join(',',$sensor_Channel);
		
		$sensor_Cool=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Cool".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Cool,$value);
		}
		$p['sensor_Cool'] = join(',',$sensor_Cool);
		
		$sensor_Spray=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Spray".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Spray,$value);
		}
		$p['sensor_Spray'] = join(',',$sensor_Spray);
		
		$sensor_Heat=array();
		for($x=0;$x<6;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_Heat".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_Heat,join(',',$tm));
		}
		$p['sensor_Heat'] = join('|',$sensor_Heat);
		
		$sensor_EX=array();
		for($x=0;$x<3;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_EX".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_EX,join(',',$tm));
		}
		$p['sensor_EX'] = join('|',$sensor_EX);
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820sysvar()
	{
		$p['rid'] = I("get.rid");
		//$p['code'] = I("code");
		$p['sys_Delay_FanUp'] = I("sys_Delay_FanUp");
		$p['sys_Delay_FanDown'] = I("sys_Delay_FanDown");
		$p['sys_Delay_HumiUp'] = I("sys_Delay_HumiUp");
		$p['sys_Delay_HumiRst'] = I("sys_Delay_HumiRst");
		$p['sys_Delay_NH3Up'] = I("sys_Delay_NH3Up");
		$p['sys_Delay_NH3Rst'] = I("sys_Delay_NH3Rst");
		$p['sys_Delay_OTemp'] = I("sys_Delay_OTemp");
		$p['sys_Delay_OTempRst'] = I("sys_Delay_OTempRst");
		$p['sys_dTemp_OTemp'] = I("sys_dTemp_OTemp");
		/*$p['sys_Time_SideWin_ON'] = I("sys_Time_SideWin_ON");
		$p['sys_Time_SideWin_OFF'] = I("sys_Time_SideWin_OFF");
		$p['sys_Time_TopWin_ON'] = I("sys_Time_TopWin_ON");
		$p['sys_Time_TopWin_OFF'] = I("sys_Time_TopWin_OFF");
		$p['sys_Time_Roller_ON'] = I("sys_Time_Roller_ON");
		$p['sys_Time_Roller_OFF'] = I("sys_Time_Roller_OFF");
		$p['sys_Time_Slide_ON'] = I("sys_Time_Slide_ON");
		$p['sys_Time_Slide_OFF'] = I("sys_Time_Slide_OFF");*/
		$sys_Time_Pos_ON=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_ON,I("sys_Time_Pos_ON".($i+1)));
		}
		$p['sys_Time_Pos_ON'] = join(',',$sys_Time_Pos_ON);
		
		$sys_Time_Pos_OFF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_OFF,I("sys_Time_Pos_OFF".($i+1)));
		}
		$p['sys_Time_Pos_OFF'] = join(',',$sys_Time_Pos_OFF);
		
		$p['sys_Delay_Return'] = I("sys_Delay_Return");
		$p['sys_Is_LimitLevel'] = I("sys_Is_LimitLevel");
		$p['sys_MaxLevel'] = I("sys_MaxLevel");
		$p['sys_Is_LevelUp_Humi'] = I("sys_Is_LevelUp_Humi");
		$p['sys_Is_LevelUp_NH3'] = I("sys_Is_LevelUp_NH3");
		$p['sys_Is_LevelUp_OTemp'] = I("sys_Is_LevelUp_OTemp");
		$p['sys_LevelUp_Max'] = I("sys_LevelUp_Max");
		
		$sys_Alarm_TempSF=array();
		for($i=0;$i<8;$i++){
			array_push($sys_Alarm_TempSF,I("sys_Alarm_TempSF".($i+1)));
		}
		$p['sys_Alarm_TempSF'] = join(',',$sys_Alarm_TempSF);
		
		$sys_Alarm_HumiSF=array();
		for($i=0;$i<2;$i++){
			array_push($sys_Alarm_HumiSF,I("sys_Alarm_HumiSF".($i+1)));
		}
		$p['sys_Alarm_HumiSF'] = join(',',$sys_Alarm_HumiSF);
		

		$p['sys_Alarm_LightSF'] = I("sys_Alarm_LightSF");
		$p['sys_Alarm_NH3'] = I("sys_Alarm_NH3");
		$p['sys_Alarm_Temp_Max'] = I("sys_Alarm_Temp_Max");
		$p['sys_Alarm_Temp_Min'] = I("sys_Alarm_Temp_Min");
		$p['sys_Alarm_dTemp_Max'] = I("sys_Alarm_dTemp_Max");
		$p['sys_Alarm_dTemp_Min'] = I("sys_Alarm_dTemp_Min");
		$p['sys_Alarm_Humi_Max'] = I("sys_Alarm_Humi_Max");
		$p['sys_Alarm_Humi_Min'] = I("sys_Alarm_Humi_Min");
		$p['sys_Alarm_Light_Min'] = I("sys_Alarm_Light_Min");
		$p['sys_Alarm_NH3_Max'] = I("sys_Alarm_NH3_Max");
		$p['sys_Password'] = I("sys_Password");
		//$p['sys_Relay'] = I("sys_Relay");
		$sys_Relay=array();
		for($i=1;$i<29;$i++){
			array_push($sys_Relay,I("sys_Relay".($i)));
		}
		$p['sys_Relay'] = join(',',$sys_Relay);
		//dump($p['sys_Relay']);
		$p['version'] = I("version");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}

	
	public function save820model()
	{
		$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		
		$p['sys_Mode'] = I("sys_Mode");
		
		$nm820=M('nm820');
		$res= $nm820->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	
	public function save820tempFig()
	{
		//$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		$nm820table=M('nm820table');
		
		$tempFig_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("tempFig_Day".($i+1));
			array_push($tempFig_Day,$value);
		}
		$p['tempFig_Day'] = join(',',$tempFig_Day);
		
		$tempFig_Target=array();
		for($i=0;$i<11;$i++){
			$value=I("tempFig_Target".($i+1));
			array_push($tempFig_Target,$value);
		}
		$p['tempFig_Target'] = join(',',$tempFig_Target);
		
		$res= $nm820table->where(" code=".$p['code'])->save($p);
		echo $res;
	}
	
	public function save820cool()
	{
		//$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		$nm820table=M('nm820table');
		
		$cool_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Day".($i+1));
			array_push($cool_Day,$value);
		}
		$p['cool_Day'] = join(',',$cool_Day);
		
		$cool_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STime".($i+1));
			array_push($cool_STime,$value);
		}
		$p['cool_STime'] = join(',',$cool_STime);
		
		$cool_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_ETime".($i+1));
			array_push($cool_ETime,$value);
		}
		$p['cool_ETime'] = join(',',$cool_ETime);
		
		$cool_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STemp".($i+1));
			array_push($cool_STemp,$value);
		}
		$p['cool_STemp'] = join(',',$cool_STemp);
		
		$cool_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_EHumi".($i+1));
			array_push($cool_EHumi,$value);
		}
		$p['cool_EHumi'] = join(',',$cool_EHumi);
		
		$cool_On=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_On".($i+1));
			array_push($cool_On,$value);
		}
		$p['cool_On'] = join(',',$cool_On);
		
		$cool_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Off".($i+1));
			array_push($cool_Off,$value);
		}
		$p['cool_Off'] = join(',',$cool_Off);
		
		$res= $nm820table->where(" code=".$p['code'])->save($p);
		echo $res;
	}
	
	public function save820spray()
	{
		//$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		$nm820table=M('nm820table');
		
		$spray_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_Day".($i+1));
			array_push($spray_Day,$value);
		}
		$p['spray_Day'] = join(',',$spray_Day);
		
		$spray_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_STime".($i+1));
			array_push($spray_STime,$value);
		}
		$p['spray_STime'] = join(',',$spray_STime);
		
		$spray_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_ETime".($i+1));
			array_push($spray_ETime,$value);
		}
		$p['spray_ETime'] = join(',',$spray_ETime);
		
		$spray_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_STemp".($i+1));
			array_push($spray_STemp,$value);
		}
		$p['spray_STemp'] = join(',',$spray_STemp);
		
		$spray_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_EHumi".($i+1));
			array_push($spray_EHumi,$value);
		}
		$p['spray_EHumi'] = join(',',$spray_EHumi);
		
		$spray_On=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_On".($i+1));
			array_push($spray_On,$value);
		}
		$p['spray_On'] = join(',',$spray_On);
		
		$spray_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_Off".($i+1));
			array_push($spray_Off,$value);
		}
		$p['spray_Off'] = join(',',$spray_Off);
		
		
		$res= $nm820table->where(" code=".$p['code'])->save($p);
		echo $res;
	}
	
	public function save820heat()
	{
		//$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		$nm820table=M('nm820table');
		
		$heat_STime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STime".($i+1));
			array_push($heat_STime,$value);
		}
		$p['heat_STime'] = join(',',$heat_STime);
		
		$heat_ETime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETime".($i+1));
			array_push($heat_ETime,$value);
		}
		$p['heat_ETime'] = join(',',$heat_ETime);
		
		$heat_STemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STemp".($i+1));
			array_push($heat_STemp,$value);
		}
		$p['heat_STemp'] = join(',',$heat_STemp);
		
		$heat_ETemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETemp".($i+1));
			array_push($heat_ETemp,$value);
		}
		$p['heat_ETemp'] = join(',',$heat_ETemp);
		
		$heat_On=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_On".($i+1));
			array_push($heat_On,$value);
		}
		$p['heat_On'] = join(',',$heat_On);
		
		$heat_Off=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_Off".($i+1));
			array_push($heat_Off,$value);
		}
		$p['heat_Off'] = join(',',$heat_Off);

		
		$res= $nm820table->where(" code=".$p['code'])->save($p);
		echo $res;
	}
	
	public function save820light()
	{
		//$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		$nm820table=M('nm820table');
		
		$light_STime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime".($i+1));
			array_push($light_STime,$value);
		}
		$p['light_STime'] = join(',',$light_STime);
		
		$light_ETime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime".($i+1));
			array_push($light_ETime,$value);
		}
		$p['light_ETime'] = join(',',$light_ETime);
		
		$light_Level=array();
		for($i=0;$i<5;$i++){
			$value=I("light_Level".($i+1));
			array_push($light_Level,$value);
		}
		$p['light_Level'] = join(',',$light_Level);
		
		$light_STime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime1".($i+1));
			array_push($light_STime1,$value);
		}
		$p['light_STime1'] = join(',',$light_STime1);
		
		$light_STime2=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime2".($i+1));
			array_push($light_STime2,$value);
		}
		$p['light_STime2'] = join(',',$light_STime2);
		
		$light_ETime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime1".($i+1));
			array_push($light_ETime1,$value);
		}
		$p['light_ETime1'] = join(',',$light_ETime1);
		
		$light_ETime2=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime2".($i+1));
			array_push($light_ETime2,$value);
		}
		$p['light_ETime2'] = join(',',$light_ETime2);
		
		$res= $nm820table->where(" code=".$p['code'])->save($p);
		echo $res;
	}
	
	public function save820wind()
	{
		//$p['rid'] = I("get.rid");
		$p['code'] = I("get.code");
		$nm820table=M('nm820table');
		
		$wind_On=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_On".($i+1));
			array_push($wind_On,$value);
		}
		$p['wind_On'] = join(',',$wind_On);
		
		$wind_Off=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Off".($i+1));
			array_push($wind_Off,$value);
		}
		$p['wind_Off'] = join(',',$wind_Off);
		
		$wind_dTemp=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_dTemp".($i+1));
			array_push($wind_dTemp,$value);
		}
		$p['wind_dTemp'] = join(',',$wind_dTemp);
		
		$wind_Side=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Side".($i+1));
			array_push($wind_Side,$value);
		}
		$p['wind_Side'] = join(',',$wind_Side);
		
		$wind_Roller=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Roller".($i+1));
			array_push($wind_Roller,$value);
		}
		$p['wind_Roller'] = join(',',$wind_Roller);
		
		$wind_VSFan=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_VSFan".($i+1));
			array_push($wind_VSFan,$value);
		}
		$p['wind_VSFan'] = join(',',$wind_VSFan);
		
		$wind_Top=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Top".($i+1));
			array_push($wind_Top,$value);
		}
		$p['wind_Top'] = join(',',$wind_Top);
		
		$wind_Slide=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Slide".($i+1));
			array_push($wind_Slide,$value);
		}
		$p['wind_Slide'] = join(',',$wind_Slide);
		
		$wind_Fan=array();
		for($i=0;$i<40;$i++){
			$value='';
			for($j=16;$j>0;$j--){
				$t=I("wind_Fan".($j)."_".($i+1));
				$value.=$t;
			}
			array_push($wind_Fan,(string)bindec($value));
		}
		$p['wind_Fan'] = join(',',$wind_Fan);
		
		//echo dump($p);
		$res= $nm820table->where(" code=".$p['code'])->save($p);
		echo $res;
	}
	
	public function readNM820clock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm820=M('nm820');
			$model = $nm820->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM820';
					$params['Type']='control';
					$params['Function']='read_clock';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function writeNM820clock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm820=M('nm820');
			$model = $nm820->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM820';
					$params['Type']='control';
					$params['Function']='set_clock';
					$params['Content']=date("Y-m-d H:i:s");
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	
	public function readNM820para(){
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm820=M('nm820');
			$model = $nm820->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM820';
					$params['Type']='read_para';
					$params['Function']='read_system_var';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg='设备离线';
						}else{
							$msg=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg = $e;
			echo ($msg);
		}
		//dump($msg);
		echo ($msg);
	}
	public function writeNM820para(){
		
		$p['sys_Mode']=I("sys_Mode");
		//统计
		$p['mh_Day']=I("mh_Day");
		$p['mh_DeadTotal']=I("mh_DeadTotal");
		$p['mh_SerNum']=I("mh_SerNum");
		$p['mh_InitNum']=I("mh_InitNum");
		$p['mh_RevNum']=I("mh_RevNum");
		
		//通讯设置
		$p['addr']=I("code");
		$p['serverIP']=I("serverIP");
		$p['serverPort']=I("serverPort");
		$p['localIP']=I("localIP");
		$p['gateway']=I("gateway");
		$p['netmask']=I("netmask");
		
		//隧道设置
		$p['tunnel_Temp']=I("tunnel_Temp");
		$p['sys_Level_StartChannel']=I("sys_Level_StartChannel");
		$p['sys_Time_Channel']=I("sys_Time_Channel");
		
		//湿度设置
		$p['humi_Target']=I("humi_Target");
		$p['humi_Max']=I("humi_Max");
		$p['humi_Min']=I("humi_Min");
		
		//氨气设置
		$p['nh3_Max']=I("nh3_Max");
		$p['nh3_dVal']=I("nh3_dVal");
		
		//传感器设置
		$sensor_Wind=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Wind".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Wind,$value);
		}
		$p['sensor_Wind'] = (string)bindec(join(array_reverse($sensor_Wind)));
		
		$sensor_Channel=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Channel".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Channel,$value);
		}
		$p['sensor_Channel'] = (string)bindec(join(array_reverse($sensor_Channel)));
		
		$sensor_Cool=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Cool".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Cool,$value);
		}
		$p['sensor_Cool'] = (string)bindec(join(array_reverse($sensor_Cool)));
		
		$sensor_Spray=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Spray".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Spray,$value);
		}
		$p['sensor_Spray'] = (string)bindec(join(array_reverse($sensor_Spray)));
		
		$sensor_Heat=array();
		for($x=0;$x<6;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_Heat".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_Heat,(string)bindec(join(array_reverse($tm))));
		}
		$p['sensor_Heat'] = $sensor_Heat;
		
		$sensor_EX=array();
		for($x=0;$x<3;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_EX".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_EX,(string)bindec(join(array_reverse($tm))));
		}
		$p['sensor_EX'] = $sensor_EX;
		
		//系统变量
		$p['sys_Delay_FanUp']=I("sys_Delay_FanUp");
		$p['sys_Delay_FanDown']=I("sys_Delay_FanDown");
		$p['sys_Delay_HumiUp']=I("sys_Delay_HumiUp");
		$p['sys_Delay_HumiRst']=I("sys_Delay_HumiRst");
		$p['sys_Delay_NH3Up']=I("sys_Delay_NH3Up");
		$p['sys_Delay_NH3Rst']=I("sys_Delay_NH3Rst");
		$p['sys_Delay_OTemp']=I("sys_Delay_OTemp");
		$p['sys_Delay_OTempRst']=I("sys_Delay_OTempRst");
		$p['sys_dTemp_OTemp']=I("sys_dTemp_OTemp");
		
		$sys_Time_Pos_ON=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_ON,I("sys_Time_Pos_ON".($i+1)));
		}
		$p['sys_Time_Pos_ON'] = $sys_Time_Pos_ON;
		
		$sys_Time_Pos_OFF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_OFF,I("sys_Time_Pos_OFF".($i+1)));
		}
		$p['sys_Time_Pos_OFF'] = $sys_Time_Pos_OFF;
		
		$p['sys_Delay_Return']=I("sys_Delay_Return");
		$p['sys_Is_LimitLevel']=I("sys_Is_LimitLevel");
		$p['sys_MaxLevel']=I("sys_MaxLevel");
		$p['sys_Is_LevelUp_Humi']=I("sys_Is_LevelUp_Humi");
		$p['sys_Is_LevelUp_NH3']=I("sys_Is_LevelUp_NH3");
		$p['sys_Is_LevelUp_OTemp']=I("sys_Is_LevelUp_OTemp");
		$p['sys_LevelUp_Max']=I("sys_LevelUp_Max");
		
		$sys_Alarm_TempSF=array();
		for($i=0;$i<8;$i++){
			array_push($sys_Alarm_TempSF,I("sys_Alarm_TempSF".($i+1)));
		}
		$p['sys_Alarm_TempSF'] = $sys_Alarm_TempSF;
		
		$sys_Alarm_HumiSF=array();
		for($i=0;$i<2;$i++){
			array_push($sys_Alarm_HumiSF,I("sys_Alarm_HumiSF".($i+1)));
		}
		$p['sys_Alarm_HumiSF'] = $sys_Alarm_HumiSF;
		
		$p['sys_Alarm_LightSF'] = I("sys_Alarm_LightSF");
		$p['sys_Alarm_NH3'] = I("sys_Alarm_NH3");
		$p['sys_Alarm_Temp_Max'] = I("sys_Alarm_Temp_Max");
		$p['sys_Alarm_Temp_Min'] = I("sys_Alarm_Temp_Min");
		$p['sys_Alarm_dTemp_Max'] = I("sys_Alarm_dTemp_Max");
		$p['sys_Alarm_dTemp_Min'] = I("sys_Alarm_dTemp_Min");
		$p['sys_Alarm_Humi_Max'] = I("sys_Alarm_Humi_Max");
		$p['sys_Alarm_Humi_Min'] = I("sys_Alarm_Humi_Min");
		$p['sys_Alarm_Light_Min'] = I("sys_Alarm_Light_Min");
		$p['sys_Alarm_NH3_Max'] = I("sys_Alarm_NH3_Max");
		//$sys_Relay = I("sys_Relay");//继电器编码变成数组
		//$p['sys_Relay']=explode(',',$sys_Relay);
		
		$sys_Relay=array();
		for($i=1;$i<29;$i++){
			array_push($sys_Relay,I("sys_Relay".($i)));
		}
		$p['sys_Relay'] = $sys_Relay;
		
		//温度曲线
		$tempFig_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("tempFig_Day".($i+1));
			array_push($tempFig_Day,$value);
		}
		$p['tempFig_Day'] = $tempFig_Day;
		
		$tempFig_Target=array();
		for($i=0;$i<11;$i++){
			$value=I("tempFig_Target".($i+1));
			array_push($tempFig_Target,$value);
		}
		$p['tempFig_Target'] = $tempFig_Target;
		
		//制冷--曲线
		$cool_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Day".($i+1));
			array_push($cool_Day,$value);
		}
		$p['cool_Day'] = $cool_Day;
		
		$cool_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STime".($i+1));
			array_push($cool_STime,$value);
		}
		$p['cool_STime'] = $cool_STime;
		
		$cool_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_ETime".($i+1));
			array_push($cool_ETime,$value);
		}
		$p['cool_ETime'] = $cool_ETime;
		
		$cool_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STemp".($i+1));
			array_push($cool_STemp,$value);
		}
		$p['cool_STemp'] = $cool_STemp;
		
		$cool_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_EHumi".($i+1));
			array_push($cool_EHumi,$value);
		}
		$p['cool_EHumi'] = $cool_EHumi;
		
		$cool_On=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_On".($i+1));
			array_push($cool_On,$value);
		}
		$p['cool_On'] = $cool_On;
		
		$cool_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Off".($i+1));
			array_push($cool_Off,$value);
		}
		$p['cool_Off'] = $cool_Off;
		
		//喷雾--曲线
		$spray_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_Day".($i+1));
			array_push($spray_Day,$value);
		}
		$p['spray_Day'] = $spray_Day;
		
		$spray_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_STime".($i+1));
			array_push($spray_STime,$value);
		}
		$p['spray_STime'] = $spray_STime;
		
		$spray_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_ETime".($i+1));
			array_push($spray_ETime,$value);
		}
		$p['spray_ETime'] = $spray_ETime;
		
		$spray_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_STemp".($i+1));
			array_push($spray_STemp,$value);
		}
		$p['spray_STemp'] = $spray_STemp;
		
		$spray_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_EHumi".($i+1));
			array_push($spray_EHumi,$value);
		}
		$p['spray_EHumi'] = $spray_EHumi;
		
		$spray_On=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_On".($i+1));
			array_push($spray_On,$value);
		}
		$p['spray_On'] = $spray_On;
		
		$spray_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("spray_Off".($i+1));
			array_push($spray_Off,$value);
		}
		$p['spray_Off'] = $spray_Off;
		
		//加热 6组
		$heat_STime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STime".($i+1));
			array_push($heat_STime,$value);
		}
		$p['heat_STime'] = $heat_STime;
		
		$heat_ETime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETime".($i+1));
			array_push($heat_ETime,$value);
		}
		$p['heat_ETime'] = $heat_ETime;
		
		$heat_STemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STemp".($i+1));
			array_push($heat_STemp,$value);
		}
		$p['heat_STemp'] = $heat_STemp;
		
		$heat_ETemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETemp".($i+1));
			array_push($heat_ETemp,$value);
		}
		$p['heat_ETemp'] = $heat_ETemp;
		
		$heat_On=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_On".($i+1));
			array_push($heat_On,$value);
		}
		$p['heat_On'] = $heat_On;
		
		$heat_Off=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_Off".($i+1));
			array_push($heat_Off,$value);
		}
		$p['heat_Off'] = $heat_Off;
		
		//光照
		$light_STime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime".($i+1));
			array_push($light_STime,$value);
		}
		$p['light_STime'] = $light_STime;
		
		$light_ETime=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime".($i+1));
			array_push($light_ETime,$value);
		}
		$p['light_ETime'] = $light_ETime;
		
		$light_Level=array();
		for($i=0;$i<5;$i++){
			$value=I("light_Level".($i+1));
			array_push($light_Level,$value);
		}
		$p['light_Level'] = $light_Level;
		
		$light_STime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime1".($i+1));
			array_push($light_STime1,$value);
		}
		$p['light_STime1'] = $light_STime1;
		
		$light_STime2=array();
		for($i=0;$i<5;$i++){
			$value=I("light_STime2".($i+1));
			array_push($light_STime2,$value);
		}
		$p['light_STime2'] = $light_STime2;
		
		$light_ETime1=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime1".($i+1));
			array_push($light_ETime1,$value);
		}
		$p['light_ETime1'] = $light_ETime1;
		
		$light_ETime2=array();
		for($i=0;$i<5;$i++){
			$value=I("light_ETime2".($i+1));
			array_push($light_ETime2,$value);
		}
		$p['light_ETime2'] = $light_ETime2;
		
		//通风级别
		$wind_On=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_On".($i+1));
			array_push($wind_On,$value);
		}
		$p['wind_On'] = $wind_On;
		
		$wind_Off=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Off".($i+1));
			array_push($wind_Off,$value);
		}
		$p['wind_Off'] = $wind_Off;
		
		$wind_dTemp=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_dTemp".($i+1));
			array_push($wind_dTemp,$value);
		}
		$p['wind_dTemp'] = $wind_dTemp;
		
		$wind_Side=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Side".($i+1));
			array_push($wind_Side,$value);
		}
		$p['wind_Side'] = $wind_Side;
		
		$wind_Roller=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Roller".($i+1));
			array_push($wind_Roller,$value);
		}
		$p['wind_Roller'] = $wind_Roller;
		
		$wind_VSFan=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_VSFan".($i+1));
			array_push($wind_VSFan,$value);
		}
		$p['wind_VSFan'] = $wind_VSFan;
		
		$wind_Top=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Top".($i+1));
			array_push($wind_Top,$value);
		}
		$p['wind_Top'] = $wind_Top;
		
		$wind_Slide=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Slide".($i+1));
			array_push($wind_Slide,$value);
		}
		$p['wind_Slide'] = $wind_Slide;
		
		/*$wind_Fan=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Fan".($i+1));
			array_push($wind_Fan,$value);
		}
		$p['wind_Fan'] = $wind_Fan;*/
		
		$wind_Fan=array();
		for($i=0;$i<40;$i++){
			$value='';
			for($j=16;$j>0;$j--){
				$t=I("wind_Fan".($j)."_".($i+1));
				$value.=$t;
			}
			array_push($wind_Fan,(string)bindec($value));
		}
		$p['wind_Fan'] = $wind_Fan;
		
		//额外系统 3组
		$ex_STime=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_STime".($i+1));
			//$value='00:00';
			array_push($ex_STime,$value);
		}
		$p['ex_STime'] = $ex_STime;
		
		$ex_ETime=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_ETime".($i+1));
			//$value='00:00';
			array_push($ex_ETime,$value);
		}
		$p['ex_ETime'] = $ex_ETime;
		
		$ex_STemp=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_STemp".($i+1));
			//$value='0.0';
			array_push($ex_STemp,$value);
		}
		$p['ex_STemp'] = $ex_STemp;
		
		$ex_ETemp=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_ETemp".($i+1));
			//$value='0.0';
			array_push($ex_ETemp,$value);
		}
		$p['ex_ETemp'] = $ex_ETemp;
		
		$ex_On=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_On".($i+1));
			//$value='0.0';
			array_push($ex_On,$value);
		}
		$p['ex_On'] = $ex_On;
		
		$ex_Off=array();
		for($i=0;$i<3;$i++){
			$value=I("ex_Off".($i+1));
			//$value='0.0';
			array_push($ex_Off,$value);
		}
		$p['ex_Off'] = $ex_Off;
		
		//校准
		$cal_dTemp=array();
		for($i=0;$i<8;$i++){
			$value=I("cal_dTemp".($i+1));
			//$value='0.0';
			array_push($cal_dTemp,$value);
		}
		$p['cal_dTemp'] = $cal_dTemp;
		
		$cal_dHumi=array();
		for($i=0;$i<2;$i++){
			$value=I("cal_dHumi".($i+1));
			//$value='0.0';
			array_push($cal_dHumi,$value);
		}
		$p['cal_dHumi'] = $cal_dHumi;
		
		$p['cal_dLight'] = I("cal_dLight");
		$p['cal_dNH3'] = I("cal_dNH3");
		$p['cal_PulseWater'] = I("cal_PulseWater");
		
		$contentJson=json_encode($p);
		

		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm820=M('nm820');
			$model = $nm820->where(" rid=".$rid)->find();

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM820';
					$params['Type']='write_para';
					$params['Function']='write_system_var';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					$len=socket_write($socket, $str, strlen($str));
					//dump($str);
					//dump($len);
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	
	public function readNM410clock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm410=M('nm410');
			$model = $nm410->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM410';
					$params['Type']='control';
					$params['Function']='read_clock';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function writeNM410clock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm410=M('nm410');
			$model = $nm410->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM410';
					$params['Type']='control';
					$params['Function']='set_clock';
					$params['Content']=date("Y-m-d H:i:s");
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function readNM410para(){
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm410=M('nm410');
			$model = $nm410->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM410';
					$params['Type']='read_para';
					$params['Function']='read_system_var';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg='设备离线';
						}else{
							$msg=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg = $e;
			echo ($msg);
		}
		//dump($msg);
		echo ($msg);
	}
	public function writeNM410para(){
		
		$p['sys_Mode']=I("sys_Mode");
		//统计
		$p['mh_Day']=I("mh_Day");
		$p['mh_DeadTotal']=I("mh_DeadTotal");
		//$p['mh_SerNum']=I("mh_SerNum");
		$p['mh_InitNum']=I("mh_InitNum");
		$p['mh_RevNum']=I("mh_RevNum");
		
		//通讯设置
		$p['addr']=I("code");
		$p['serverIP']=I("serverIP");
		$p['serverPort']=I("serverPort");
		$p['localIP']=I("localIP");
		$p['gateway']=I("gateway");
		$p['netmask']=I("netmask");
		
		//隧道设置
		$p['tunnel_Temp']=I("tunnel_Temp");
		$p['sys_Level_StartChannel']=I("sys_Level_StartChannel");
		$p['sys_Time_Channel']=I("sys_Time_Channel");
		
		
		//传感器设置
		$sensor_Wind=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Wind".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Wind,$value);
		}
		$p['sensor_Wind'] = (string)bindec(join(array_reverse($sensor_Wind)));
		
		$sensor_Channel=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Channel".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Channel,$value);
		}
		$p['sensor_Channel'] = (string)bindec(join(array_reverse($sensor_Channel)));
		
		$sensor_Cool=array();
		for($i=0;$i<8;$i++){
			$value=I("sensor_Cool".($i+1));
			$value=(empty($value)?'0':'1');//empty = 0
			array_push($sensor_Cool,$value);
		}
		$p['sensor_Cool'] = (string)bindec(join(array_reverse($sensor_Cool)));

		
		$sensor_Heat=array();
		for($x=0;$x<3;$x++){
			$tm=array();
			for($i=0;$i<8;$i++){
				$value=I("sensor_Heat".($x+1).($i+1));
				$value=(empty($value)?'0':'1');//empty = 0
				array_push($tm,$value);
			}
			array_push($sensor_Heat,(string)bindec(join(array_reverse($tm))));
		}
		$p['sensor_Heat'] = $sensor_Heat;
		
		
		//系统变量
		$p['sys_Delay_FanUp']=I("sys_Delay_FanUp");
		$p['sys_Delay_FanDown']=I("sys_Delay_FanDown");

		
		$sys_Time_Pos_ON=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_ON,I("sys_Time_Pos_ON".($i+1)));
		}
		$p['sys_Time_Pos_ON'] = $sys_Time_Pos_ON;
		
		$sys_Time_Pos_OFF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Time_Pos_OFF,I("sys_Time_Pos_OFF".($i+1)));
		}
		$p['sys_Time_Pos_OFF'] = $sys_Time_Pos_OFF;
		
		
		$sys_Alarm_TempSF=array();
		for($i=0;$i<4;$i++){
			array_push($sys_Alarm_TempSF,I("sys_Alarm_TempSF".($i+1)));
		}
		$p['sys_Alarm_TempSF'] = $sys_Alarm_TempSF;
		
		$sys_Alarm_HumiSF=array();
		for($i=0;$i<1;$i++){
			array_push($sys_Alarm_HumiSF,I("sys_Alarm_HumiSF".($i+1)));
		}
		$p['sys_Alarm_HumiSF'] = $sys_Alarm_HumiSF;
		
		$p['sys_Alarm_Temp_Max'] = I("sys_Alarm_Temp_Max");
		$p['sys_Alarm_Temp_Min'] = I("sys_Alarm_Temp_Min");
		$p['sys_Alarm_Humi_Max'] = I("sys_Alarm_Humi_Max");
		$p['sys_Alarm_Humi_Min'] = I("sys_Alarm_Humi_Min");
		$p['sys_EnHumi'] = I("sys_EnHumi");
		
		$sys_Relay=array();
		for($i=1;$i<17;$i++){
			array_push($sys_Relay,I("sys_Relay".($i)));
		}
		$p['sys_Relay'] = $sys_Relay;
		
		//温度曲线
		$tempFig_Day=array();
		for($i=0;$i<8;$i++){
			$value=I("tempFig_Day".($i+1));
			array_push($tempFig_Day,$value);
		}
		$p['tempFig_Day'] = $tempFig_Day;
		
		$tempFig_Target=array();
		for($i=0;$i<8;$i++){
			$value=I("tempFig_Target".($i+1));
			array_push($tempFig_Target,$value);
		}
		$p['tempFig_Target'] = $tempFig_Target;
		
		//制冷--曲线
		$cool_Day=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Day".($i+1));
			array_push($cool_Day,$value);
		}
		$p['cool_Day'] = $cool_Day;
		
		$cool_STime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STime".($i+1));
			array_push($cool_STime,$value);
		}
		$p['cool_STime'] = $cool_STime;
		
		$cool_ETime=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_ETime".($i+1));
			array_push($cool_ETime,$value);
		}
		$p['cool_ETime'] = $cool_ETime;
		
		$cool_STemp=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_STemp".($i+1));
			array_push($cool_STemp,$value);
		}
		$p['cool_STemp'] = $cool_STemp;
		
		$cool_EHumi=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_EHumi".($i+1));
			array_push($cool_EHumi,$value);
		}
		$p['cool_EHumi'] = $cool_EHumi;
		
		$cool_On=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_On".($i+1));
			array_push($cool_On,$value);
		}
		$p['cool_On'] = $cool_On;
		
		$cool_Off=array();
		for($i=0;$i<11;$i++){
			$value=I("cool_Off".($i+1));
			array_push($cool_Off,$value);
		}
		$p['cool_Off'] = $cool_Off;

		//加热 6组
		$heat_STime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STime".($i+1));
			array_push($heat_STime,$value);
		}
		$p['heat_STime'] = $heat_STime;
		
		$heat_ETime=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETime".($i+1));
			array_push($heat_ETime,$value);
		}
		$p['heat_ETime'] = $heat_ETime;
		
		$heat_STemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_STemp".($i+1));
			array_push($heat_STemp,$value);
		}
		$p['heat_STemp'] = $heat_STemp;
		
		$heat_ETemp=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_ETemp".($i+1));
			array_push($heat_ETemp,$value);
		}
		$p['heat_ETemp'] = $heat_ETemp;
		
		$heat_On=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_On".($i+1));
			array_push($heat_On,$value);
		}
		$p['heat_On'] = $heat_On;
		
		$heat_Off=array();
		for($i=0;$i<6;$i++){
			$value=I("heat_Off".($i+1));
			array_push($heat_Off,$value);
		}
		$p['heat_Off'] = $heat_Off;
		
		
		
		//通风级别
		$wind_On=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_On".($i+1));
			array_push($wind_On,$value);
		}
		$p['wind_On'] = $wind_On;
		
		$wind_Off=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Off".($i+1));
			array_push($wind_Off,$value);
		}
		$p['wind_Off'] = $wind_Off;
		
		$wind_dTemp=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_dTemp".($i+1));
			array_push($wind_dTemp,$value);
		}
		$p['wind_dTemp'] = $wind_dTemp;
		
		$wind_Side=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Side".($i+1));
			array_push($wind_Side,$value);
		}
		$p['wind_Side'] = $wind_Side;
		
		$wind_Roller=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Roller".($i+1));
			array_push($wind_Roller,$value);
		}
		$p['wind_Roller'] = $wind_Roller;
		
		$wind_VSFan=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_VSFan".($i+1));
			array_push($wind_VSFan,$value);
		}
		$p['wind_VSFan'] = $wind_VSFan;
		
		$wind_Top=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Top".($i+1));
			array_push($wind_Top,$value);
		}
		$p['wind_Top'] = $wind_Top;
		
		$wind_Slide=array();
		for($i=0;$i<20;$i++){
			$value=I("wind_Slide".($i+1));
			array_push($wind_Slide,$value);
		}
		$p['wind_Slide'] = $wind_Slide;
		
		/*$wind_Fan=array();
		for($i=0;$i<40;$i++){
			$value=I("wind_Fan".($i+1));
			array_push($wind_Fan,$value);
		}
		$p['wind_Fan'] = $wind_Fan;*/
		
		$wind_Fan=array();
		for($i=0;$i<20;$i++){
			$value='';
			for($j=8;$j>0;$j--){
				$t=I("wind_Fan".($j)."_".($i+1));
				$value.=$t;
			}
			array_push($wind_Fan,(string)bindec($value));
		}
		$p['wind_Fan'] = $wind_Fan;
		

		//校准
		$cal_dTemp=array();
		for($i=0;$i<4;$i++){
			$value=I("cal_dTemp".($i+1));
			//$value='0.0';
			array_push($cal_dTemp,$value);
		}
		$p['cal_dTemp'] = $cal_dTemp;
		
		$cal_dHumi=array();
		for($i=0;$i<1;$i++){
			$value=I("cal_dHumi".($i+1));
			//$value='0.0';
			array_push($cal_dHumi,$value);
		}
		$p['cal_dHumi'] = $cal_dHumi;
		
		$contentJson=json_encode($p);

		//echo($contentJson);
		try{
			$params = array();
			$rid = I("get.rid");
			$code = I("get.code");
			
			$nm410=M('nm410');
			$model = $nm410->where(" rid=".$rid)->find();

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$code;
					$params['Device']='NM410';
					$params['Type']='write_para';
					$params['Function']='write_system_var';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	
	
	//bw800
	public function savebw800(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("lxcode");
		$p['routename'] = I("routename");$p['routepass'] = I("routepass");$p['serverip'] = I("serverip");$p['serverport'] = I("serverport");
		$p['mode'] = I("mode");$p['xlper'] = I("xlper");$p['xlspace'] = I("xlspace");$p['waterauto'] = I("waterauto");
		$p['watertime'] = I("watertime");$p['waterspace'] = I("waterspace");$p['usepass'] = I("usepass");$p['canover'] = I("canover");
		$p['idlebl'] = I("idlebl");$p['eatdelay'] = I("eatdelay");
		$bw800=M('bw800');
		$model = $bw800->where(" rid=".$p['rid'])->find();
		$res= $bw800->where(" rid=".$p['rid'])->save($p);
		
		$bw800cal=M('bw800caltable');
		$bw800calList=$bw800cal->where(" lxcode='".$p['lxcode']."'")->select();
		for($i=0;$i<count($bw800calList);$i++){
			$index= $bw800calList[$i]['index'];
			$bw800calList[$i]['weight']=I("weight".$index);
			$res=$bw800cal->save($bw800calList[$i]);
			if($res<0){
				break;
			}
		}
		echo $res;
	}
	public function savecqsetting(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("lxcode");
		
		$p['cqsettingday'] = I("cqsettingday");
		$p['cqsettingcode'] = I("cqsettingcode");
		
		//dump($p);
		$bw800=M('bw800');
		$model = $bw800->where(" rid=".$p['rid'])->select()[0];
		$res= $bw800->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	public function savebrsetting(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("lxcode");
		
		$p['brsettingday'] = I("brsettingday");
		$p['brsettingcode'] = I("brsettingcode");
		$p['brsettingbabycount'] = I("brsettingbabycount");
		
		//dump($p);
		$bw800=M('bw800');
		$model = $bw800->where(" rid=".$p['rid'])->select()[0];
		$res= $bw800->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	public function updateBW800AddrVar(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("lxcode");
		
		$p['routename'] = I("routename");$p['routepass'] = I("routepass");$p['serverip'] = I("serverip");$p['serverport'] = I("serverport");
		
		//dump($p);
		$bw800=M('bw800');
		$model = $bw800->where(" rid=".$p['rid'])->select()[0];
		$res= $bw800->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	public function updateBW800SystemVar(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");
		$p['mode'] = I("mode");$p['xlper'] = I("xlper");$p['xlspace'] = I("xlspace");$p['waterauto'] = I("waterauto");
		$p['watertime'] = I("watertime");$p['waterspace'] = I("waterspace");$p['usepass'] = I("usepass");$p['canover'] = I("canover");
		$p['idlebl'] = I("idlebl");$p['eatdelay'] = I("eatdelay");
		
		$bw800=M('bw800');
		$model = $bw800->where(" rid=".$p['rid'])->select()[0];
		$res= $bw800->where(" rid=".$p['rid'])->save($p);
		echo $res;
	}
	public function updateBW800TimeTable(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");
		
		$res=0;
		$bw800time=M('bw800timetable');
		$bw800timeList=$bw800time->where(" lxcode='".$p['lxcode']."'")->select();
		for($i=0;$i<count($bw800timeList);$i++){
			$index= $bw800timeList[$i]['index'];
			$bw800timeList[$i]['timestart']=I("timestart".$index);
			$bw800timeList[$i]['timeend']=I("timeend".$index);
			$bw800timeList[$i]['percent']=I("percent".$index);
			
			$res=$bw800time->save($bw800timeList[$i]);
			//dump($bw800timeList[$i]);
			//dump($res);
			if($res<0){
				break;
			}
		}
		echo $res;
	}
	public function updateBW800CalTable(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");
		
		$res=0;
		$bw800cal=M('bw800caltable');
		$bw800calList=$bw800cal->where(" lxcode='".$p['lxcode']."'")->select();
		for($i=0;$i<count($bw800calList);$i++){
			$index= $bw800calList[$i]['index'];
			$bw800calList[$i]['weight']=I("weight".$index);
			$res=$bw800cal->save($bw800calList[$i]);
			if($res<0){
				break;
			}
		}
		echo $res;
	}
	public function updateBW800ccTable(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");
		
		$res=0;
		$bw800cc=M('bw800cctable');
		$bw800ccList=$bw800cc->where(" lxcode='".$p['lxcode']."'")->select();
		for($i=0;$i<count($bw800ccList);$i++){
			$day= $bw800ccList[$i]['day'];
			$bw800ccList[$i]['weight']=I("ccweight".$day);
			$res=$bw800cc->save($bw800ccList[$i]);
			if($res<0){
				break;
			}
		}
		echo $res;
	}
	public function updateBW800jcTable(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");
		
		$res=0;
		$bw800jc=M('bw800jctable');
		$bw800jcList=$bw800jc->where(" lxcode='".$p['lxcode']."'")->select();
		
		for($i=0;$i<count($bw800jcList);$i++){
			$day= $bw800jcList[$i]['day'];
			//dump($day);
			$bw800jcList[$i]['weight']=I("jcweight".$day);
			$res=$bw800jc->save($bw800jcList[$i]);
			if($res<0){
				break;
			}
		}
		echo $res;
	}
	public function readBW800clock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='control';
					$params['Function']='read_clock';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function writeBW800clock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='control';
					$params['Function']='set_clock';
					$params['Content']=date("Y-m-d H:i:s");
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function readBW800para(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='read_para';
					$params['Function']='read_system_var';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg='设备离线';
						}else{
							$msg=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg = $e;
			echo ($msg);
		}
		//dump($msg);
		echo ($msg);
	}
	public function writeBW800para(){

		$p['addr'] = I("lxcode");
		$p['routeName'] = I("routename");
		$p['routepass'] = I("routepass");
		$p['serverip'] = I("serverip");
		$p['serverport'] = I("serverport");
		$p['mode'] = I("mode");
		$p['xlper'] = I("xlper");
		$p['xlspace'] = "1";
		$p['waterauto'] = I("waterauto");
		$p['watertime'] = I("watertime");
		$p['waterspace'] = I("waterspace");
		$p['usePass'] = I("usepass");
		$p['canover'] = I("canover");
		$p['idlebl'] = I("idlebl");
		$p['eatdelay'] = I("eatdelay");
		
		$timeTStart=array();
		for($i=1;$i<=10;$i++){
			array_push($timeTStart,I("timestart".$i));
		}
		
		$timeTEnd=array();
		for($i=1;$i<=10;$i++){
			array_push($timeTEnd,I("timeend".$i));
		}
		
		$timeTAmount=array();
		for($i=1;$i<=10;$i++){
			array_push($timeTAmount,I("percent".$i));
		}
		
		$calTable=array();
		for($i=1;$i<=10;$i++){
			array_push($calTable,I("weight".$i));
		}
		
		$totalTable_cc=array();
		for($i=-8;$i<=18;$i++){
			array_push($totalTable_cc,I("ccweight".$i));
		}
		
		$totalTable_jc=array();
		for($i=-8;$i<=18;$i++){
			array_push($totalTable_jc,I("jcweight".$i));
		}
		
		
		$p['timeTStart']=$timeTStart;
		$p['timeTEnd']=$timeTEnd;
		$p['timeTAmount']=$timeTAmount;
		$p['calTable']=$calTable;
		$p['totalTable_cc']=$totalTable_cc;
		$p['totalTable_jc']=$totalTable_jc;
		
		$contentJson=json_encode($p);

		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='write_para';
					$params['Function']='write_system_var';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function cqsetting(){

		$p['cqsettingday'] = I("cqsettingday");
		$p['cqsettingcode'] = I("cqsettingcode");
		$contentJson=json_encode($p);

		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='control';
					$params['Function']='cqsetting';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function brsetting(){

		$p['brsettingday'] = I("brsettingday");
		$p['brsettingcode'] = I("brsettingcode");
		$p['brsettingbabycount'] = I("brsettingbabycount");
		$contentJson=json_encode($p);

		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='control';
					$params['Function']='brsetting';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function dnsetting(){
		$contentJson='1';

		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='control';
					$params['Function']='dnsetting';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function feed(){
		$contentJson='';

		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$bw800=M('bw800');
			$model = $bw800->where(" rid=".$rid)->select()[0];

			$address = C('SERVER_ADDRESS');
			$port = C('HOST_PORT');
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='BW800';
					$params['Type']='control';
					$params['Function']='feed';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	
	//nm3000
	public function savenm3000(){
		$p['rid'] = I("get.rid");
		//$p['lxcode'] = I("get.lxcode");
		$p['lxname'] = I("lxname");
		$p['lxcode'] = I("lxcode");
		$p['serveraddr'] = I("serveraddr");
		$p['localip'] = I("localip");
		$p['localgateway'] = I("localgateway");
		$p['localmask'] = I("localmask");
		
		$p['xlcount'] = I("xlcount");$p['jl_delay'] = I("jl_delay");$p['hllmkg'] = I("hllmkg");
		$p['autoclearn'] = I("autoclearn");$p['needpwd'] = I("needpwd");$p['xlopentime'] = I("xlopentime");
		$p['xlclosetime'] = I("xlclosetime");$p['xlkeeptime'] = I("xlkeeptime");$p['slstopdelay'] = I("slstopdelay");$p['slmaxtime'] = I("slmaxtime");
		$p['slmaxdl'] = I("slmaxdl");$p['sldlc'] = I("sldlc");
		$p['slmaxdltime'] = I("slmaxdltime");$p['sllimitdl'] = I("sllimitdl");$p['sllimitdltime'] = I("sllimitdltime");$p['slkzdl'] = I("slkzdl");
		$p['slkzdltime'] = I("slkzdltime");$p['mlkgcheck'] = I("mlkgcheck");
		
		for($i=1;$i<=20;$i++){
			$p['sl'.$i] = I("sl".$i);
		}
		
		for($i=1;$i<=20;$i++){
			$p['xl'.$i] = I("xl".$i);
		}
		$nm3000=M('nm3000');
		$model = $nm3000->where(" rid=".$p['rid'])->find();
		$res= $nm3000->where(" rid=".$p['rid'])->save($p);
		
		
		$p1['lxcode'] = $p['lxcode'];
		for($i=1;$i<=20;$i++){
			$p1['sltime'.$i] = I("sl".$i);
		}
		$nm3000sltime=M('nm3000sltime');
		if(!empty($p1['lxcode'])){
			$res=$nm3000sltime->where(" lxcode=".$p1['lxcode'])->save($p1);
		}else{
			$res=$nm3000sltime->add($p1);
		}
		
		$p2['lxcode'] = $p['lxcode'];
		for($i=1;$i<=20;$i++){
			$p2['xltime'.$i] = I("xl".$i);
		}
		$nm3000xltime=M('nm3000xltime');
		if(!empty($p2['lxcode'])){
			$res=$nm3000xltime->where(" lxcode=".$p2['lxcode'])->save($p2);
		}else{
			$res=$nm3000xltime->add($p2);
		}
		
		echo $res;
	}
	public function updateBasic(){
		$p['rid'] = I("rid");
		$p['lxname'] = I("lxname");
		$p['lxcode'] = I("lxcode");
		$p['serveraddr'] = I("serveraddr");
		$p['localip'] = I("localip");
		$p['localgateway'] = I("localgateway");
		$p['localmask'] = I("localmask");
		
		$nm3000=M('nm3000');
		$model = $nm3000->where(" rid=".$p['rid'])->select()[0];
		//dump($model);
		$res= $nm3000->where(" rid=".$p['rid'])->save($p);
		//dump($res);
		echo $res;
	}
	public function updateSytem(){
		$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");
		
		$p['xlcount'] = I("xlcount");$p['jl_delay'] = I("jl_delay");$p['hllmkg'] = I("hllmkg");
		$p['autoclearn'] = I("autoclearn");$p['needpwd'] = I("needpwd");$p['xlopentime'] = I("xlopentime");
		$p['xlclosetime'] = I("xlclosetime");$p['xlkeeptime'] = I("xlkeeptime");$p['slstopdelay'] = I("slstopdelay");$p['slmaxtime'] = I("slmaxtime");
		$p['slmaxdl'] = I("slmaxdl");$p['sldlc'] = I("sldlc");
		$p['slmaxdltime'] = I("slmaxdltime");$p['sllimitdl'] = I("sllimitdl");$p['sllimitdltime'] = I("sllimitdltime");$p['slkzdl'] = I("slkzdl");
		$p['slkzdltime'] = I("slkzdltime");$p['mlkgcheck'] = I("mlkgcheck");
		
		for($i=1;$i<=20;$i++){
			$p['sl'.$i] = I("sl".$i);
		}
		
		for($i=1;$i<=20;$i++){
			$p['xl'.$i] = I("xl".$i);
		}
		
		$nm3000=M('nm3000');
		$model = $nm3000->where(" rid=".$p['rid'])->select()[0];
		//dump($model);
		$res= $nm3000->where(" rid=".$p['rid'])->save($p);
		//dump($res);
		echo $res;
	}
	public function updateSltime(){
		//$p['rid'] = I("get.rid");
		$p['lxcode'] = I("get.lxcode");

		for($i=1;$i<=20;$i++){
			$p['sltime'.$i] = I("sl".$i);
		}
		
		$nm3000sltime=M('nm3000sltime');

		if(!empty($p['lxcode'])){
			$res=$nm3000sltime->where(" lxcode=".$p['lxcode'])->save($p);
		}else{
			$res=$nm3000sltime->add($p);
		}
		
		echo $res;
	}
	public function updateXltime(){
		$p['lxcode'] = I("get.lxcode");
		
		for($i=1;$i<=20;$i++){
			$p['xltime'.$i] = I("xl".$i);
		}
		
		$nm3000xltime=M('nm3000xltime');

		if(!empty($p['lxcode'])){
			$res=$nm3000xltime->where(" lxcode=".$p['lxcode'])->save($p);
		}else{
			$res=$nm3000xltime->add($p);
		}
		
		echo $res;
	}
	public function readpara(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$nm3000=M('nm3000');
			$model = $nm3000->where(" rid=".$rid)->select()[0];
			$serveraddr=explode(':',$model['serveraddr']);

			//dump($serveraddr);
			//开始同步服务器
			$address = $serveraddr[0];
			$port = $serveraddr[1];
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='NM3000';
					$params['Type']='read_para';
					$params['Function']='read_system_var';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg='设备离线';
						}else{
							$msg=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg = $e;
			echo ($msg);
		}
		echo ($msg);
	}
	public function writepara(){

		$p['xlcount'] = I("xlcount");$p['jl_delay'] = I("jl_delay");$p['hllmkg'] = I("hllmkg");
		$p['autoclearn'] = I("autoclearn");$p['needpwd'] = I("needpwd");$p['xlopentime'] = I("xlopentime");
		$p['xlclosetime'] = I("xlclosetime");$p['xlkeeptime'] = I("xlkeeptime");$p['slstopdelay'] = I("slstopdelay");$p['slmaxtime'] = I("slmaxtime");
		$p['slmaxdl'] = I("slmaxdl");$p['sldlc'] = I("sldlc");
		$p['slmaxdltime'] = I("slmaxdltime");$p['sllimitdl'] = I("sllimitdl");$p['sllimitdltime'] = I("sllimitdltime");$p['slkzdl'] = I("slkzdl");
		$p['slkzdltime'] = I("slkzdltime");$p['mlkgcheck'] = I("mlkgcheck");
		
		$sltab=array();
		for($i=1;$i<=20;$i++){
			array_push($sltab,I("sl".$i));
		}
		
		$xltab=array();
		for($i=1;$i<=20;$i++){
			array_push($xltab,I("xl".$i));
		}
		$p['sltab']=$sltab;
		$p['xltab']=$xltab;
		
		$contentJson=json_encode($p);

		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$nm3000=M('nm3000');
			$model = $nm3000->where(" rid=".$rid)->select()[0];
			$serveraddr=explode(':',$model['serveraddr']);

			//dump($serveraddr);
			//开始同步服务器
			$address = $serveraddr[0];
			$port = $serveraddr[1];
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='NM3000';
					$params['Type']='write_para';
					$params['Function']='write_system_var';
					$params['Content']=$contentJson;
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function setSlModel(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			$value = I("get.value");
			
			$nm3000=M('nm3000');
			$model = $nm3000->where(" rid=".$rid)->select()[0];
			$serveraddr=explode(':',$model['serveraddr']);

			//dump($serveraddr);
			//开始同步服务器
			$address = $serveraddr[0];
			$port = $serveraddr[1];
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='NM3000';
					$params['Type']='control';
					$params['Function']='set_sl';
					$params['Content']=($value?'1':'0');
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							if($json['Content']==='OK'){
								//保存数据库
								$model['slmodel']=$value;
								$nm3000->save($model);
							}
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function setxlModel(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			$value = I("get.value");
			
			$nm3000=M('nm3000');
			$model = $nm3000->where(" rid=".$rid)->select()[0];
			$serveraddr=explode(':',$model['serveraddr']);

			//dump($serveraddr);
			//开始同步服务器
			$address = $serveraddr[0];
			$port = $serveraddr[1];
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='NM3000';
					$params['Type']='control';
					$params['Function']='set_xl';
					$params['Content']=($value?'1':'0');
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							if($json['Content']==='OK'){
								//保存数据库
								$model['xlmodel']=$value;
								$nm3000->save($model);
							}
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function readclock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$nm3000=M('nm3000');
			$model = $nm3000->where(" rid=".$rid)->select()[0];
			$serveraddr=explode(':',$model['serveraddr']);

			
			//开始同步服务器
			$address = $serveraddr[0];
			$port = $serveraddr[1];
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			//dump($address);dump($port);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					//sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='NM3000';
					$params['Type']='control';
					$params['Function']='read_clock';
					$params['Content']='';
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
	public function writeclock(){
		try{
			$params = array();
			$rid = I("get.rid");
			$lxcode = I("get.lxcode");
			
			$nm3000=M('nm3000');
			$model = $nm3000->where(" rid=".$rid)->select()[0];
			$serveraddr=explode(':',$model['serveraddr']);

			//dump($serveraddr);
			//开始同步服务器
			$address = $serveraddr[0];
			$port = $serveraddr[1];
			$timeout = C('TCP_TIMEOUT');
			$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,array("sec"=>$timeout, "usec"=>0));//接受超时
			socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,array("sec"=>$timeout, "usec"=>0));//发送超时
			if ($socket){
				$result = socket_connect($socket, $address, $port);
				if($result){
					sleep(1);//延时1s
					//组成报文发送
					$params=array();
					$params['Session']='123456';
					$params['Code']=$lxcode;
					$params['Device']='NM3000';
					$params['Type']='control';
					$params['Function']='set_clock';
					$params['Content']=date("Y-m-d H:i:s");
					$str=json_encode($params);
					
					socket_write($socket, $str, strlen($str));
					//$count=socket_send($socket, $str, strlen($str),MSG_EOF);
					while ($res = socket_read($socket, 8192)) {
						//返回
						$json=json_decode($res,true);
						if($json['Function']=='Offline'){
							$msg['message']="设备离线";
						}else{
							$msg['message']=$json['Content'];
						}
						break;
					}
				}
				else{
					$msg['message'] = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket));
				}
			}
			else{
				$msg['message'] = "socket_create error";
			}
			socket_close($socket);
		}
		catch(Exception $e){
			$msg['message'] = $e;
			echo json_encode($msg);
		}
		echo json_encode($msg);
	}
}